def _init_db(self): if not self._owned_games_db: self._owned_games_db = DBClient(self._client.owned_games_db_path) if not self._local_games_db: self._local_games_db = DBClient( self._client.installed_games_db_path)
def process(self, request): start_time = time.time() client = DBClient() client.connect() req = db_pb2.DBRequest() res = db_pb2.DBResponse() req.ParseFromString(request) res.seq_id = req.seq_id status = -1 for query in req.query: logger.debug("process query[sql=%s]" % query) result = res.result.add() if query.type == Query.SELECT: status = self._select(client, query, result) elif query.type == Query.INSERT: status = self._insert(client, query, result) elif query.type == Query.UPDATE: status = self._update(client, query, result) elif query.type == Query.DELETE: status = self._delete(client, query, result) if status != 0: break client.commit() res.status = status consume_time = int((time.time() - start_time) * 1000) logger.notice("Query[req=%s][res=%s][consume=%d ms]" % (req, res, consume_time)) return res.SerializeToString()
def main(): args = parse_args() if args.debug: logging.getLogger().setLevel(logging.DEBUG) config = None with open(args.config) as config_file: config = json.load(config_file) db = DBClient(config) command = commands.get(args.command) if command: command(db, args) else: logging.error(f'command {args.command} is not supported') sys.exit(1)
def __init__(self): # Clients self.db = DBClient() self.registry = RegistryClient() # All setflag locks in the current tick self.setflag_locks = [] # A lock that guards self.setflag_locks self.setflag_locks_list_lock = threading.Lock() # Logs self.log = logging.getLogger('scriptbot.scheduler') self.log.setLevel(settings.LOG_LEVEL) self.log.addHandler( logstash.TCPLogstashHandler(LOGSTASH_IP, LOGSTASH_PORT, version=1)) self.log.info('#' * 80) self.log.info("Initialization") self.log.info('#' * 80)
# -*- encoding: utf-8 -*- from db_client import DBClient from lxml import etree import json import codecs d = DBClient() class HTMLBuilder(object): """ build htmls which include forms - search, add, edit + view mode saves hierarchial structure of data using embedded divs """ def __init__(self): info = json.loads( codecs.open("html_info.json", 'r', encoding='utf-8').read()) self.fields = info['field_types'] self.blocks = info['blocks'] self.subblocks = info['subblocks'] self.order = info['order'] self.labels = info['labels'] self.choices = info['choices'] self.from_db = info['choices_from_db'] self.buttons = info['buttons'] self.parser = etree.HTMLParser() def create_html(self, values, mode,
from spotify_api_client import SpotifyClientAPI import spotify_api_processor from db_client import DBClient client_id = os.getenv('spotify_client_id') client_secret = os.getenv('spotify_client_secret') DATABASE_URL = os.getenv('DATABASE_URL') playlist_uri = sys.argv[1] access_token = sys.argv[2] api_client = SpotifyClientAPI(client_id=client_id, client_secret=client_secret, access_token=access_token) db_client = DBClient(DATABASE_URL=DATABASE_URL) playlist_id = spotify_api_processor.get_playlist_id(playlist_uri=playlist_uri) playlist_name = api_client.get_playlist_info(playlist_id=playlist_id, fields='name')['name'] playlist_tracks = api_client.get_playlist_tracks(playlist_id=playlist_id) db_client.create_table() for item in playlist_tracks['items']: track_id = item['track']['id'] track_uri = item['track']['uri'] track_features = api_client.get_track_features(track_id=track_id, track_uri=track_uri) if track_features == {}: continue
def __init__(self): super(Treets, self).__init__() self.db_client = DBClient() self.data_converter = DataConverter()
def __init__(self): self.db = DBClient()
def _init_db(self): if not self._owned_games_db and self._client.is_installed: self._owned_games_db = DBClient(self._client.owned_games_db_path)
def get_receiver_user_id_str(tweet, receiver_screen_name): for mention in tweet["entities"]["user_mentions"]: if mention["screen_name"] == receiver_screen_name: return mention["id"] raise Exception("not match receiver_user") if __name__ == '__main__': config = toml.load(open(config_path)) t_client = TwitterClient(config["twitter"]) w_client = WalletClient(config["wallet"]) d_client = DBClient(config["database"]) print("Worker Run") timeline = t_client.stream_bot_timeline() for line in timeline.iter_lines(): try: tweet = json.loads(line.decode("utf-8")) tweet_id_str = tweet["id_str"] # リプライ時に利用する sender_user_id_str = tweet["user"]["id_str"] sender_user_screen_name = tweet["user"]["screen_name"] tweet_dict = tweet["text"].split(" ") # Botへのメンションチェック if tweet_dict[0] != t_client.bot_name: