Python database.Database() Examples
The following are 30
code examples of database.Database().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
database
, or try the search function
.
Example #1
Source File: trader.py From Crypto-Trading-Bot with MIT License | 6 votes |
def create_balance_object(self, balance_item): """ Creates a new balance object containing only the relevant values and the BTC value of the coin's balance :param balance_item: The Bittrex user balance object for a coin :type balance_item: dict """ btc_price = 1 is_tracked = False if balance_item["Currency"] != "BTC": coin_pair = "BTC-" + balance_item["Currency"] is_tracked = coin_pair in self.Database.trades["trackedCoinPairs"] btc_price = self.get_current_price(coin_pair, "bid") try: btc_value = round(btc_price * balance_item["Balance"], 8) except TypeError as exception: logger.exception(exception) btc_value = 0 return py_.assign( py_.pick(balance_item, "Currency", "Balance"), {"BtcValue": btc_value, "IsTracked": is_tracked} )
Example #2
Source File: sync.py From plugin.video.emby with GNU General Public License v3.0 | 6 votes |
def patch_music(self, notification=False): ''' Patch the music database to silence the rescan prompt. ''' if kodi_version() < 18: LOG.info("version not supported for patching music db.") return with self.library.database_lock: with Database('music') as musicdb: self.library.kodi_media['Music'](musicdb.cursor).disable_rescan(musicdb.path.split('MyMusic')[1].split('.db')[0], 0) settings('MusicRescan.bool', True) if notification: dialog("notification", heading="{emby}", message=_('task_success'), icon="{emby}", time=1000, sound=False)
Example #3
Source File: sync.py From plugin.video.emby with GNU General Public License v3.0 | 6 votes |
def boxsets(self, library_id=None, dialog=None): ''' Process all boxsets. ''' Movies = self.library.media['Movies'] with self.library.database_lock: with Database() as videodb: with Database('emby') as embydb: obj = Movies(self.server, embydb, videodb, self.direct_path) for items in server.get_items(library_id, "BoxSet", False, self.sync['RestorePoint'].get('params')): self._restore_point(items['RestorePoint']) start_index = items['RestorePoint']['params']['StartIndex'] for index, boxset in enumerate(items['Items']): dialog.update(int((float(start_index + index) / float(items['TotalRecordCount']))*100), heading="%s: %s" % (_('addon_name'), _('boxsets')), message=boxset['Name']) obj.boxset(boxset)
Example #4
Source File: sync.py From plugin.video.emby with GNU General Public License v3.0 | 6 votes |
def musicvideos(self, library, dialog): ''' Process musicvideos from a single library. ''' MusicVideos = self.library.media['MusicVideos'] with self.library.database_lock: with Database() as videodb: with Database('emby') as embydb: obj = MusicVideos(self.server, embydb, videodb, self.direct_path) for items in server.get_items(library['Id'], "MusicVideo", False, self.sync['RestorePoint'].get('params')): self._restore_point(items['RestorePoint']) start_index = items['RestorePoint']['params']['StartIndex'] for index, mvideo in enumerate(items['Items']): dialog.update(int((float(start_index + index) / float(items['TotalRecordCount']))*100), heading="%s: %s" % (_('addon_name'), library['Name']), message=mvideo['Name']) obj.musicvideo(mvideo, library=library) if self.update_library: self.musicvideos_compare(library, obj, embydb)
Example #5
Source File: service.py From plugin.video.emby with GNU General Public License v3.0 | 6 votes |
def check_version(self): ''' Check the database version to ensure we do not need to do a reset. ''' with Database('emby') as embydb: version = emby_db.EmbyDatabase(embydb.cursor).get_version() LOG.info("---[ db/%s ]", version) if version and compare_version(version, "3.1.0") < 0: resp = dialog("yesno", heading=_('addon_name'), line1=_(33022)) if not resp: LOG.warn("Database version is out of date! USER IGNORED!") dialog("ok", heading=_('addon_name'), line1=_(33023)) raise Exception("User backed out of a required database reset") else: reset() raise Exception("Completed database reset")
Example #6
Source File: database_test.py From gabenizer with MIT License | 6 votes |
def test_record_post(self, mock_dt): mock_dt.now.return_value = _FIXED_DATETIME db = database.Database() record = db.record_post( source_url='https://i.imgur.com/source.jpg', uploaded_url='https://i.imgur.com/upload.jpg' ) self.assertEqual( record, database.Record( source_url='https://i.imgur.com/source.jpg', uploaded_url='https://i.imgur.com/upload.jpg', success=True, date=_FIXED_DATETIME ) )
Example #7
Source File: tasks.py From od-database with MIT License | 6 votes |
def __init__(self): self.search = ElasticSearchEngine(config.ES_URL, config.ES_INDEX) self.db = database.Database(config.DB_CONN_STR) self.tracker = TaskTrackerApi(config.TT_API) self.bucket = WsBucketApi(config.WSB_API, config.WSB_SECRET) self._indexer_threads = list() self.worker = Worker.from_file(self.tracker) if not self.worker: self.worker = self.tracker.make_worker("$oddb_master") if not self.worker: print("Could not create worker: %s" % traceback.format_exc()) return self.worker.dump_to_file() self.worker.request_access(config.TT_CRAWL_PROJECT, False, True) self.worker.request_access(config.TT_INDEX_PROJECT, True, False)
Example #8
Source File: flask_server.py From trusat-backend with Apache License 2.0 | 5 votes |
def before_request_func(): # Read config and set up database connection CONFIG = os.path.abspath("../trusat-config.yaml") g.db = database.Database(CONFIG)
Example #9
Source File: consumer.py From openwhisk-package-kafka with Apache License 2.0 | 5 votes |
def __disableTrigger(self, status_code): self.setDesiredState(Consumer.State.Disabled) # when failing to establish a database connection, mark the consumer as dead to restart the consumer try: self.database = Database() self.database.disableTrigger(self.trigger, status_code) except Exception as e: logging.error('[{}] Uncaught exception: {}'.format(self.trigger, e)) self.__recordState(Consumer.State.Dead) finally: self.database.destroy()
Example #10
Source File: update_SATCAT_UCS_from_source.py From trusat-backend with Apache License 2.0 | 5 votes |
def update_celestrak_satcat_table(Database, df): log.info("Updating the celestrak_satcat table...") data_batch = [] for row in df.itertuples(index=False, name=None): record_fingerprint = fingerprint_line("".join(str(e) for e in row)) savable = [format(i) for i in row] + [record_fingerprint] data_batch.append(savable) if len(data_batch) > 0: db.add_celestrak_satcat_batch(data_batch) # make it print to the console.
Example #11
Source File: update_SATCAT_UCS_from_source.py From trusat-backend with Apache License 2.0 | 5 votes |
def update_ucs_satdb_table(Database, df): log.info("Updating the (corrected) ucs_satdb table...") total_rows = 0 data_batch = [] for row in df.itertuples(index=False, name=None): record_fingerprint = fingerprint_line("".join(str(e) for e in row)) savable = [format(i) for i in row] + [record_fingerprint] data_batch.append(savable) total_rows = total_rows + 1 if len(data_batch) > 0: db.add_ucs_satdb_batch(data_batch)
Example #12
Source File: update_SATCAT_UCS_from_source.py From trusat-backend with Apache License 2.0 | 5 votes |
def update_ucs_satdb_raw_table(Database, df): log.info("Updating the ucs_satdb_raw table...") total_rows = 0 data_batch = [] for row in df.itertuples(index=False, name=None): record_fingerprint = fingerprint_line("".join(str(e) for e in row)) savable = [format(i) for i in row] + [record_fingerprint] data_batch.append(savable) total_rows = total_rows + 1 if len(data_batch) > 0: db.add_ucs_satdb_raw_batch(data_batch)
Example #13
Source File: service.py From openwhisk-package-kafka with Apache License 2.0 | 5 votes |
def __init__(self): Thread.__init__(self) self.daemon = True self.database = Database()
Example #14
Source File: database_test.py From gabenizer with MIT License | 5 votes |
def test_contains(self): db = database.Database() self.assertTrue( db.contains('https://i.imgur.com/ZClFAdK.jpg') )
Example #15
Source File: full_sync.py From jellyfin-kodi with GNU General Public License v3.0 | 5 votes |
def video_database_locks(self): with self.library.database_lock: with Database() as videodb: with Database('jellyfin') as jellyfindb: yield videodb, jellyfindb
Example #16
Source File: full_sync.py From jellyfin-kodi with GNU General Public License v3.0 | 5 votes |
def music(self, library, dialog): ''' Process artists, album, songs from a single library. ''' with self.library.music_database_lock: with Database('music') as musicdb: with Database('jellyfin') as jellyfindb: obj = Music(self.server, jellyfindb, musicdb, self.direct_path) for items in server.get_artists(library['Id'], False, self.sync['RestorePoint'].get('params')): self.sync['RestorePoint'] = items['RestorePoint'] start_index = items['RestorePoint']['params']['StartIndex'] for index, artist in enumerate(items['Items']): percent = int((float(start_index + index) / float(items['TotalRecordCount'])) * 100) message = artist['Name'] dialog.update(percent, heading="%s: %s" % (translate('addon_name'), library['Name']), message=message) obj.artist(artist, library=library) for albums in server.get_albums_by_artist(artist['Id']): for album in albums['Items']: obj.album(album) for songs in server.get_items(album['Id'], "Audio"): for song in songs['Items']: dialog.update(percent, message="%s/%s/%s" % (message, album['Name'][:7], song['Name'][:7])) obj.song(song) for songs in server.get_songs_by_artist(artist['Id']): for song in songs['Items']: dialog.update(percent, message="%s/%s" % (message, song['Name'])) obj.song(song) if self.update_library: self.music_compare(library, obj, jellyfindb)
Example #17
Source File: full_sync.py From jellyfin-kodi with GNU General Public License v3.0 | 5 votes |
def get_libraries(self, library_id=None): with Database('jellyfin') as jellyfindb: if library_id is None: return jellyfin_db.JellyfinDatabase(jellyfindb.cursor).get_views() else: return jellyfin_db.JellyfinDatabase(jellyfindb.cursor).get_view(library_id)
Example #18
Source File: database_test.py From gabenizer with MIT License | 5 votes |
def test_record_failure(self, mock_dt): mock_dt.now.return_value = _FIXED_DATETIME db = database.Database() record = db.record_failure('https://i.imgur.com/failed.png') self.assertEqual( record, database.Record( source_url='https://i.imgur.com/failed.png', uploaded_url='', success=False, date=_FIXED_DATETIME ) )
Example #19
Source File: controller.py From super-simple-distributed-keras with MIT License | 5 votes |
def main(): """Toy example of adding jobs to be processed.""" db = Database('blog-test') while True: print("Creating job.") network = gen_network(784, 10) # mnist settings add_job('mnist', network, db) sleep_time = random.randint(60, 120) print("Waiting %d seconds." % (sleep_time)) time.sleep(sleep_time)
Example #20
Source File: service.py From openwhisk-package-kafka with Apache License 2.0 | 5 votes |
def run(self): self.canaryGenerator.start() self.lastCanaryTime = datetime.now() while True: try: if self.database is not None: logging.info("Shutting down existing DB client") self.database.destroy() logging.info("Starting changes feed") self.database = Database(timeout=changesFeedTimeout) self.changes = self.database.changesFeed(timeout=changesFeedTimeout, since=self.lastSequence) for change in self.changes: # change could be None because the changes feed will timeout # if it hasn't detected any changes. This timeout allows us to # check whether or not the feed is capable of detecting canary # documents if change != None: self.__handleDocChange(change) # Record the sequence in case the changes feed needs to be # restarted. This way the new feed can pick up right where # the old one left off. self.lastSequence = change['seq'] except Exception as e: logging.error('[canary] Exception caught from changes feed. Restarting changes feed...') logging.error(e) self.stopChangesFeed() logging.debug("[changes] I made it out of the changes loop!")
Example #21
Source File: library.py From jellyfin-kodi with GNU General Public License v3.0 | 5 votes |
def run(self): with self.lock, self.database as kodidb, Database('jellyfin') as jellyfindb: while True: try: item = self.queue.get(timeout=1) except Queue.Empty: break if item['Type'] == 'Movie': obj = Movies(self.args[0], jellyfindb, kodidb, self.args[1]).remove elif item['Type'] in ['Series', 'Season', 'Episode']: obj = TVShows(self.args[0], jellyfindb, kodidb, self.args[1]).remove elif item['Type'] in ['MusicAlbum', 'MusicArtist', 'AlbumArtist', 'Audio']: obj = Music(self.args[0], jellyfindb, kodidb, self.args[1]).remove elif item['Type'] == 'MusicVideo': obj = MusicVideos(self.args[0], jellyfindb, kodidb, self.args[1]).remove try: obj(item['Id']) except LibraryException as error: if error.status == 'StopCalled': break except Exception as error: LOG.exception(error) self.queue.task_done() if window('jellyfin_should_stop.bool'): break LOG.info("--<[ q:removed/%s ]", id(self)) self.is_done = True
Example #22
Source File: library.py From jellyfin-kodi with GNU General Public License v3.0 | 5 votes |
def run(self): with Database('jellyfin') as jellyfindb: database = jellyfin_db.JellyfinDatabase(jellyfindb.cursor) while True: try: item_id = self.queue.get(timeout=1) except Queue.Empty: break try: media = database.get_media_by_id(item_id) if media: self.output[media].put({'Id': item_id, 'Type': media}) else: items = database.get_media_by_parent_id(item_id) if not items: LOG.info("Could not find media %s in the jellyfin database.", item_id) else: for item in items: self.output[item[1]].put({'Id': item[0], 'Type': item[1]}) except Exception as error: LOG.exception(error) self.queue.task_done() if window('jellyfin_should_stop.bool'): break LOG.info("--<[ q:sort/%s ]", id(self)) self.is_done = True
Example #23
Source File: library.py From jellyfin-kodi with GNU General Public License v3.0 | 5 votes |
def run(self): with self.lock, self.database as kodidb, Database('jellyfin') as jellyfindb: while True: try: item = self.queue.get(timeout=1) except Queue.Empty: break try: if item['Type'] == 'Movie': Movies(self.args[0], jellyfindb, kodidb, self.args[1]).userdata(item) elif item['Type'] in ['Series', 'Season', 'Episode']: TVShows(self.args[0], jellyfindb, kodidb, self.args[1]).userdata(item) elif item['Type'] == 'MusicAlbum': Music(self.args[0], jellyfindb, kodidb, self.args[1]).album(item) elif item['Type'] == 'MusicArtist': Music(self.args[0], jellyfindb, kodidb, self.args[1]).artist(item) elif item['Type'] == 'AlbumArtist': Music(self.args[0], jellyfindb, kodidb, self.args[1]).albumartist(item) elif item['Type'] == 'Audio': Music(self.args[0], jellyfindb, kodidb, self.args[1]).song(item) except LibraryException as error: if error.status == 'StopCalled': break except Exception as error: LOG.exception(error) self.queue.task_done() if window('jellyfin_should_stop.bool'): break LOG.info("--<[ q:userdata/%s ]", id(self)) self.is_done = True
Example #24
Source File: library.py From jellyfin-kodi with GNU General Public License v3.0 | 5 votes |
def __init__(self, queue, lock, database, *args): self.queue = queue self.lock = lock self.database = Database(database) self.args = args threading.Thread.__init__(self)
Example #25
Source File: library.py From jellyfin-kodi with GNU General Public License v3.0 | 5 votes |
def __init__(self, queue, notify, lock, database, server=None, direct_path=None, *args): self.queue = queue self.notify_output = notify self.notify = settings('newContent.bool') self.lock = lock self.database = Database(database) self.args = args self.server = server self.direct_path = direct_path threading.Thread.__init__(self)
Example #26
Source File: library.py From jellyfin-kodi with GNU General Public License v3.0 | 5 votes |
def test_databases(self): ''' Open the databases to test if the file exists. ''' with Database('video'), Database('music'): pass
Example #27
Source File: views.py From jellyfin-kodi with GNU General Public License v3.0 | 5 votes |
def remove_library(self, view_id): ''' Remove entry from view table in jellyfin database. ''' with Database('jellyfin') as jellyfindb: jellyfin_db.JellyfinDatabase(jellyfindb.cursor).remove_view(view_id) self.delete_playlist_by_id(view_id) self.delete_node_by_id(view_id)
Example #28
Source File: views.py From jellyfin-kodi with GNU General Public License v3.0 | 5 votes |
def add_library(self, view): ''' Add entry to view table in jellyfin database. ''' with Database('jellyfin') as jellyfindb: jellyfin_db.JellyfinDatabase(jellyfindb.cursor).add_view(view['Id'], view['Name'], view['Media'])
Example #29
Source File: harvest_public_document.py From Belati with GNU General Public License v2.0 | 5 votes |
def __init__(self): self.db = Database() self.project_id = 0
Example #30
Source File: views.py From plugin.video.emby with GNU General Public License v3.0 | 5 votes |
def remove_library(self, view_id): ''' Remove entry from view table in emby database. ''' with Database('emby') as embydb: emby_db.EmbyDatabase(embydb.cursor).remove_view(view_id) self.delete_playlist_by_id(view_id) self.delete_node_by_id(view_id)