コード例 #1
0
ファイル: view.py プロジェクト: mmjbot/muslogger
def dummy():
	""" Debugging page for creating a dummy play """
	play = Play(artist = "Artist", album_artist = "Album Artist", album = "Album", title = "Title", user = users.get_current_user())
	play.put()
	print(datetime.datetime.now())
	print(play.time)
	print(play.time.hour)
	return "Success"	
コード例 #2
0
ファイル: view.py プロジェクト: mmjbot/muslogger
def log():
	""" Log a play """
	# play = Play(artist = "Artist", album_artist = "Album Artist", album = "Album", title = "Title", user = users.get_current_user())
	play = Play(artist=request.form['artist'],
		album_artist=request.form['album_artist'],
		album=request.form['album'],
		title=request.form['title'],
		timezone=request.form['tz'],
		user=users.get_current_user())
	play.put()
	print("logged song")
	# flash('Play saved on database.')
	return "Success"
コード例 #3
0
ファイル: server.py プロジェクト: ellakcd/site_maker
def add_play():
    """add play info to database"""

    user_id = session["current_user"]

    kwargs = dict(
        user_id=user_id,
        title=request.form.get("title"),
        playwright=request.form.get("playwright"),
        character=request.form.get("character"),
        theater=request.form.get("theater"),
        director=request.form.get("director"),
        link=request.form.get("link"),
    )

    keys_to_remove = []

    for key in kwargs.keys():
        if kwargs[key] == "":
            keys_to_remove.append(key)
    for key in keys_to_remove:
        del kwargs[key]
    db.session.add(Play(**kwargs))
    db.session.commit()

    return redirect("users/{}/my_resume".format(user_id))
コード例 #4
0
ファイル: view.py プロジェクト: mmjbot/muslogger
def hello():
    """Return a friendly HTTP greeting."""
    plays = filter(lambda p: p.user == users.get_current_user(), Play.all())
    print(plays)
    logout_url = users.create_logout_url('/home')
    logout_url_linktext = 'Logout'
    login_url = users.create_login_url('/home')
    login_url_linktext = 'Login'
    plays = sorted(plays, key=lambda x: x.time)
    return render_template('list_plays.html', plays=plays, logout_url=logout_url, logout_url_linktext=logout_url_linktext, login_url=login_url, login_url_linktext=login_url_linktext)
コード例 #5
0
def load_plays():
	"""Load plays from seed data into database"""

	with open("seed_data/plays.txt") as plays: 
		for row in plays: 
			play = row.rstrip().split("|")

			hidden = True if play[11] == "True" else False

			kwargs = dict(
			play_id = play[0],
			user_id = play[1],
			resume_order = play[2], 
			review_order = play[3],
			title = play[4],
			playwright = play[5],
			character = play[6],
			theater = play[7],
			director = play[8],
			link = play[9], 
			category = play[10], 
			hidden = hidden 
			)

			keys_to_remove = []

			for key in kwargs.keys(): 
				if kwargs[key] == "":
					keys_to_remove.append(key)

			for key in keys_to_remove:
				del kwargs[key]

			play = Play(**kwargs)

			db.session.add(play)

	db.session.commit()
コード例 #6
0
ファイル: seed.py プロジェクト: rooharrigan/Line-Pls
def load_plays(file_name):
    """Loads plays from Works.txt into database"""

    #Uses python csv.reader function to parse data from txt file
    with open(file_name) as csvfile:
        playreader = csv.reader(csvfile, delimiter=',', quotechar='~')
        for row in playreader:
            play_id = row[0]
            title = row[1]
            long_title = row[2]
            date = row[3]
            genre_id = row[4]

            #Connects data from Works.txt to variables in the plays table
            play = Play(play_id=play_id,
                        title=title,
                        long_title=long_title,
                        date=date,
                        genre_id=genre_id)

            #Adds the play to the play table in the database.
            db.session.add(play)
        db.session.commit()
コード例 #7
0
ファイル: station.py プロジェクト: fluxTH/RadioLogger4
    def process_data(self, parsed):
        """
        parsed = {
            id: int
            type: str<SONG, LINK, SPOT, DEFAULT_METADATA>
            title: str
            artist: str
            album: str optional
            extra_data: Dict nullable, Extra play data
            extra_asset_data: Dict nullable, Extra asset data
        }
        """

        assetType = 'Unknown'
        if parsed['type'] == 'SONG':
            assetType = 'Song'
        elif parsed['type'] == 'LINK':
            assetType = 'Link'
        elif parsed['type'] == 'SPOT':
            assetType = 'Spot'
        elif parsed['type'] == 'DEFAULT_METADATA':
            assetType = 'Live'

        new_record = False

        if parsed['type'] == 'DEFAULT_METADATA':
            asset = self._dbObj.assets.filter_by(id_by_station=-1).first()
        else:
            if 'id' in parsed:
                # check if asset exists
                q = self._dbObj.assets.filter_by(id_by_station=parsed['id'])
                if q.count() < 1:
                    # if not exists then create one
                    asset = Asset(
                        station = self._dbObj,
                        id_by_station = parsed['id'],
                        type = assetType,
                        title = parsed['title'],
                        artist = parsed['artist'],
                        album = parsed['album'] if 'album' in parsed else None,
                        extra_data = json.dumps(parsed['extra_asset_data'], sort_keys=True)
                            if 'extra_asset_data' in parsed and parsed['extra_asset_data'] != {}
                            else None,
                    )
                    new_record = True
                else:
                    asset = q.first()
            else:
                # check if asset exists
                q = self._dbObj.assets.filter_by(title=parsed['title'], artist=parsed['artist'])
                if q.count() < 1:
                    # if not exists then create one
                    asset = Asset(
                        station = self._dbObj,
                        id_by_station = None,
                        type = assetType,
                        title = parsed['title'],
                        artist = parsed['artist'],
                        album = parsed['album'] if 'album' in parsed else None,
                        extra_data = json.dumps(parsed['extra_asset_data'], sort_keys=True)
                            if 'extra_asset_data' in parsed and parsed['extra_asset_data'] != {}
                            else None,
                    )
                    new_record = True
                else:
                    asset = q.first()

            if new_record:
                self._dbSess.add(asset)
                # self._dbSess.commit()

        # TODO: Update outdated assets

        # check if duplicate play
        playq = self._dbSess.query(Play).filter(Play.asset.has(station=self._dbObj)).order_by(desc(Play.id)).limit(1)
        last_play = playq.first()

        play = Play(
            asset = asset,
            extra_data = json.dumps(parsed['extra_data'], sort_keys=True)
                if 'extra_data' in parsed and parsed['extra_data'] != {}
                else None,
        )

        dupe = True
        if last_play is None:
            dupe = False
        else:
            if 'id' in parsed:
                if play.asset.id_by_station != last_play.asset.id_by_station:
                    dupe = False
            else:
                if play.asset.title != last_play.asset.title and play.asset.artist != last_play.asset.artist:
                    dupe = False

        if not dupe:
            # add asset to plays
            self._dbSess.add(play)
            # self._dbSess.commit()
            print('not last')
        else:

            print('is last')

        return (asset, play)