Exemplo n.º 1
0
 def default_album(self):
     album = m.Album.select(lambda rv: rv.user_id == self.id and rv.role == 'default').first()
     if not album:
         album = m.Album(user_id=self.id,
                         name=u'默认专辑',
                         role='default').save()
     return album
Exemplo n.º 2
0
def init_db():
    db.create_all()
    db.session.commit()

    # Default groups
    public_group = models.Group(name='public')
    db.session.add(public_group)
    loggedin_group = models.Group(name='loggedin')
    db.session.add(loggedin_group)
    admin_group = models.Group(name='admin')
    db.session.add(admin_group)

    # Useful groups
    kennis_group = models.Group(name='kennis')
    db.session.add(kennis_group)
    familie_group = models.Group(name='familie')
    db.session.add(familie_group)

    with open(os.path.join(app.root_path, 'pw.txt'), 'r') as fp:
        pw = fp.read().strip()

    admin_user = models.User(
        name='Thomas',
        email='*****@*****.**',
        pwhash=werkzeug.security.generate_password_hash(pw))
    admin_user.groups.append(admin_group)
    db.session.add(admin_user)

    loggedin_user = models.User(
        name='test-loggedin',
        email='*****@*****.**',
        pwhash=werkzeug.security.generate_password_hash(pw))
    db.session.add(loggedin_user)

    kennis_user = models.User(
        name='test-kennis',
        email='*****@*****.**',
        pwhash=werkzeug.security.generate_password_hash(pw))
    kennis_user.groups.append(kennis_group)
    db.session.add(kennis_user)

    familie_user = models.User(
        name='test-familie',
        email='*****@*****.**',
        pwhash=werkzeug.security.generate_password_hash(pw))
    familie_user.groups.append(familie_group)
    db.session.add(familie_user)

    album = models.Album(name='uploads')
    db.session.add(album)

    db.session.commit()
Exemplo n.º 3
0
def putAlbum(title, artist, tracks, add_date=None, asin=None, 
             cover_small=None, cover_large=None, isNew=True):
  if add_date is None:
    add_date = datetime.datetime.now()

  album_fake_key = db.Key.from_path("Album", 1)
  batch = db.allocate_ids(album_fake_key, 1)
  album_key = db.Key.from_path('Album', batch[0])

  song_keys = [putSong(title=trackname,
                       artist=artist,
                       album=album_key,
                       ).key()
               for trackname in tracks]

  tryPutArtist(artist)

  album = models.Album(
    key=album_key,
    title=title,
    lower_title=title.lower(),
    artist=artist,
    add_date=add_date,
    isNew=isNew,
    songList=song_keys,
    )

  if cover_small is not None:
    album.cover_small = cover_small
  if cover_large is not None:
    album.cover_large = cover_large
  if asin is not None:
    album.asin = asin

  album.put()

  if isNew:
    pass

  return mcset(album, ALBUM_ENTRY, album.key())
Exemplo n.º 4
0
        song_json = json.loads(songs[0].text)
    except Exception,e:
        sys.stderr.write(str(e)+album_name+songs[0].text)
        return None
    save_songs(song_json)
    pic_url = song_json[0]["album"]["picUrl"]
    r = des[0].get('content')
    l = r.split(u'。')
    sname = l[0].split(u':')[-1]
    date = l[1].split(u':')[-1]
    cop =  l[2].split(u':')[-1]
    des =  ''.join(l[3:-1])
    album = models.Album(aid = album_id,\
                        singer = singer_name[0],\
                        name = album_name,\
                        release_date = date,\
                        publisher = cop,\
                        pic_url = pic_url,\
                        description = des)
    try:
        album.save()
    except Exception,e:
        models.db.rollback()
        sys.stderr.write('album.save: aid= '+ str(album_id)+str(e))
    song_dict = {}
    for e in song_json:
        name = e["name"]
        comment_thread = e["commentThreadId"]
        song_dict[name] = comment_thread 
    return song_dict
Exemplo n.º 5
0
import models, request, time

URL = raw_input('Enter the URL of the first image: ')
ALBUM_NAME = raw_input('Enter the album name: ')
DIR_NAME = raw_input(
    'Enter the directory name (leave blank to use album name): ')
IMAGE_SELECTOR = raw_input('Enter the image selector to search for: ')
NEXT_SELECTOR = raw_input('Enter the next selector to search for: ')

# extract album name
URL_COMPONENTS = URL.split('/')
ALBUM_NAME = ALBUM_NAME if ALBUM_NAME else URL_COMPONENTS[
    URL_COMPONENTS.index('album') + 1]

# instantiate album
ALBUM = models.Album(ALBUM_NAME, DIR_NAME)
current_page = request.Page(URL, {
    'image': IMAGE_SELECTOR,
    'next': NEXT_SELECTOR
})

running = True

startTime = time.time()
flushTimer = time.time()

totalCount = 0

while running:
    img_url = current_page.extract_img()
 def addNewAlbum(self):
     newAlbum = models.Album("Unknown Artist", "New Album Title")
     self.albums.append(newAlbum)
     self.view.setAlbums(self.albums)
     self.view.setSelectedAlbum(self.albums.index(newAlbum))
     self.loadViewFromModel()