当前位置: 首页>>代码示例>>Python>>正文


Python DbSession.add方法代码示例

本文整理汇总了Python中yt_crawler.backend.database.DbSession.add方法的典型用法代码示例。如果您正苦于以下问题:Python DbSession.add方法的具体用法?Python DbSession.add怎么用?Python DbSession.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yt_crawler.backend.database.DbSession的用法示例。


在下文中一共展示了DbSession.add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: insert_contants

# 需要导入模块: from yt_crawler.backend.database import DbSession [as 别名]
# 或者: from yt_crawler.backend.database.DbSession import add [as 别名]
 def insert_contants():
     if not ErrorFatality.exists(error_name='info'):
         DbSession.add(ErrorFatality(error_name='info'))
     if not ErrorFatality.exists(error_name='warning'):
         DbSession.add(ErrorFatality(error_name='warning'))
     if not ErrorFatality.exists(error_name='error'):
         DbSession.add(ErrorFatality(error_name='error'))
     if not ErrorFatality.exists(error_name='severe'):
         DbSession.add(ErrorFatality(error_name='severe'))
开发者ID:Sheldan,项目名称:yt_crawler,代码行数:11,代码来源:youtube_model.py

示例2: import_data

# 需要导入模块: from yt_crawler.backend.database import DbSession [as 别名]
# 或者: from yt_crawler.backend.database.DbSession import add [as 别名]
def import_data():
    LOG.info('Importing data')
    for video_type in database.get_all_video_types():
        DbSession.add(VideoType(video_type_id=video_type['ID'], name=video_type['NAME']))

    for youtuber in database.get_all_youtuber():
        DbSession.add(
            Youtuber(channel_id=youtuber['channelId'], channel_title=youtuber['name'],
                     avatar_url=youtuber['avatarUrl']))
    VideoType.setup_constants()

    for video in database.get_all_videos():
        if video['downloadedDate'] is not None:
            DbSession.add(Video(video_id=video['videoId'], channel_id=video['channelId'],
                                to_be_converted=utils.get_bool_from_int(video['convert']), size=video['size'],
                                downloaded_date=datetime.datetime.fromtimestamp(
                                    int(round(int(video['downloadedDate']) / 1000))), path=video['path'],
                                name=video['name'],
                                resolution=video['resolution'],
                                duration=video['duration'], stored=utils.get_bool_from_int(video['stored']),
                                scheduled=utils.get_bool_from_int(video['scheduled']),
                                start_time=datetime.datetime.fromtimestamp(
                                    int(round(float(video['startTime']) / 1000))) if
                                video['startTime'] is not None else None,
                                sticky=utils.get_bool_from_int(video['sticky']),
                                type=int(video['type'])))
        else:
            DbSession.add(
                Video(video_id=video['videoId'], channel_id=video['channelId'], video_type=VideoType.EXISTING,
                      stored=False, sticky=False, to_be_converted=False, scheduled=False))

    for playlist in database.get_all_playlists():
        DbSession.add(Playlist(playlist_name=playlist['playlistName'], playlist_id=playlist['playlistId'],
                               to_crawl=utils.get_bool_from_int(playlist['toCrawl']),
                               local=utils.get_bool_from_int(playlist['local']),
                               title_pattern=playlist['titlePattern']))

    for youtuber in database.get_all_statistic():
        DbSession.add(Statistic(channel_id=youtuber['channelId'], type=int(youtuber['videoType']),
                                size_downloaded=int(youtuber['sizeDownloaded']),
                                number_downloaded=int(youtuber['numberDownloaded'])))

    for album in database.get_albums():
        DbSession.add(Album(album_id=album['albumId'], name=album['name'] if album['name'] else ''))

    for artist in database.get_artists():
        DbSession.add(Artist(artist_id=artist['artistId'], name=artist['name'] if artist['name'] else ''))

    for cover in database.get_all_covers():
        DbSession.add(
            Cover(cover_id=cover['coverId'], cover=cover['cover'], content_type=cover['contentType'],
                  hash=cover['hash']))

    for audio in database.get_all_audio_files_normal():
        DbSession.add(Audio(audio_id=audio['audioId'], video_id=audio['videoId'],
                            converted_date=datetime.datetime.fromtimestamp(
                                int(round(float(audio['convertedDate']) / 1000))),
                            path=audio['path'], stored=utils.get_bool_from_int(audio['stored']),
                            artist_id=audio['artistId'],
                            album_id=audio['albumId'], cover_id=audio['coverId'], genre=audio['genre'],
                            year=audio['year'],
                            rating=audio['rating'], title=audio['title']))

    for playlist_item in database.get_all_playlist_items():
        DbSession.add(PlaylistItem(video_id=playlist_item['videoId'], playlist_id=playlist_item['playlistId'],
                                   position=playlist_item['position']))

    for profile in database.get_all_profiles():
        DbSession.add(Profile(profile_name=profile['profileName'], profile_id=profile['profileId']))

    for profile_item in database.get_all_profile_items():
        DbSession.add(YoutuberInProfile(channel_id=profile_item['channelId'], profile_id=profile_item['profileId'],
                                        filter_criteria=profile_item['filterCriteria'],
                                        position=profile_item['position'],
                                        force_update=profile_item['forceUpdate']))

    for background in database.get_all_backgrounds():
        DbSession.add(
            Background(background_id=background['backgroundId'], path=background['path'], width=background['width'],
                       height=background['height'], top_margin=background['topMargin'],
                       left_margin=background['leftMargin'], y_position=background['yPosition'],
                       x_position=background['xPosition'], background_size_x=background['backgroundSizeX'],
                       background_size_y=background['backgroundSizeY']))

    for user in database.get_all_user():
        DbSession.add(
            User(user_id=user['userId'], user_name=user['userName'], password=user['password'], role=user['role'],
                 background_id=user['backgroundId']))

    for scheduled_video in database.get_all_scheduled_videos():
        DbSession.add(ScheduledVideo(video_id=scheduled_video['videoId'], scheduled_ad=scheduled_video['scheduledAt']))

    for error_fatality in database.get_all_error_fatalities():
        DbSession.add(ErrorFatality(id=error_fatality['id'], error_name=error_fatality['errorName']))

    ErrorLog.setup_constants()
    # for error_log in database.get_all_error_logs():
    #     session.add(ErrorLog(error_id=error_log['errorId'], error_fatality=error_log['errorFatality'], error_message=error_log['errorMessage'], error_location=error_log['errorLocation'],
    #                         occurrence_date=datetime.datetime.fromtimestamp(int(round(int(error_log['occurrenceDate']) / 1000))),
    #                          stack_trace=error_log['stacktrace'], hidden=error_log['hidden']))
#.........这里部分代码省略.........
开发者ID:Sheldan,项目名称:yt_crawler,代码行数:103,代码来源:importer.py

示例3: create_without_transaction

# 需要导入模块: from yt_crawler.backend.database import DbSession [as 别名]
# 或者: from yt_crawler.backend.database.DbSession import add [as 别名]
 def create_without_transaction(cls, **kwargs):
     instance = cls(**kwargs)
     DbSession.add(instance)
     return instance
开发者ID:Sheldan,项目名称:yt_crawler,代码行数:6,代码来源:mixins.py

示例4: create

# 需要导入模块: from yt_crawler.backend.database import DbSession [as 别名]
# 或者: from yt_crawler.backend.database.DbSession import add [as 别名]
 def create(cls, **kwargs):
     instance = cls(**kwargs)
     DbSession.add(instance)
     return instance
开发者ID:Sheldan,项目名称:yt_crawler,代码行数:6,代码来源:mixins.py


注:本文中的yt_crawler.backend.database.DbSession.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。