def __init__(self, server): ''' Init the Api with Ice objects created. ''' FS.Api.__init__(self) self.server = server self.manager = ApiManager(server)
def try_fill_cell(csv_file, ids, break_after=None): i = 0 if break_after: ids = ids[0:break_after] with ApiManager() as manager: videos = manager.get_videos(ids) with open(csv_file, errors='ignore') as csv_in: header = csv_in.readline() with open(os.path.join('out', csv_file), 'w', errors='ignore') as csv_out: csv_out.write(header) for row in csv_in.readlines(): try: video = videos[row.split(';')[0]] row_to_write = str(video) + '\n' except Exception as e: row_to_write = [r for r in row.split(';')] row_to_write[14] = 'True' row_to_write = ';'.join(row_to_write) print(e) csv_out.write(row_to_write) i += 1 if break_after and i == break_after: break
def __init__(self, config): threading.Thread.__init__(self) self._intersec = 1 self._thread_stop = False self._monitor = None new_gm_uid = config.generate_new_gm_uid() self._device_model = config.device_model self._api_mgr = ApiManager(new_gm_uid, config.attached_client_uid) self.setup_descriptors() if self._platform == common.PLATFORM_IOS: self._monitor = iOSMonitor(self._device_descriptor, self._app_descriptor) elif self._platform == common.PLATFORM_ANDROID: self._monitor = androidMonitor(self._device_descriptor, self._app_descriptor) self.setup_log()
def __init__(self, config): self.config = config self.logger.set_level(self.config['log_level']) self.population_size = self.config['population_size'] self.population = self.generate_initial_population() # Initialize api manager -- maybe by reference in the future O: self.api_manager = ApiManager(config) # Warmup API Manager while not self.api_manager.is_warm: sleep(1) else: self.logger.progress('API Manager is warm') # Housekeeping for later self.population_first_frame_price = None
def main(): """ Main part """ ### Create Databases and tables ### cnx = mysql.connector.connect(user=USER, password=PASSWORD,host=HOST) cursor = cnx.cursor() create_db(cursor, cnx) populate_tables(cursor) ### Fetch the data from the API ### api_manager = ApiManager() categories = api_manager.categories() for category in categories: if category['products'] > MIN_PRODUCTS_PER_CATEGORY: ### Category ### cursor.execute("INSERT INTO `category` (name, url, tag) VALUES (%s, %s, %s)" ,(category['name'], category['url'], category['id'])) category_index = cursor.lastrowid print("Category added ") cnx.commit() ### Products ### products = api_manager.category_products(category['id']) for product in products: try: print(product['product_name']) cursor.execute("INSERT INTO `product` (name, description, stores, grade, link, fat, sugars, salt, saturated_fat) \ VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)", (product['product_name'], product['generic_name_fr'], product['stores'], \ product['nutrition_grades'], product['link'], product['nutrient_levels']['fat'], product['nutrient_levels']['sugars'], \ product['nutrient_levels']['salt'], product['nutrient_levels']['saturated-fat'])) product_index = cursor.lastrowid except KeyError: pass print("Product added ") cnx.commit() ### Mutual table ### cursor.execute("INSERT INTO `categories_products` (category_id, product_id) \ VALUES (%s, %s)", (category_index, product_index))
def system_update(): try: flog("SYSTEM UPDATE") key = request.form['key'] am = ApiManager(key) token = am.get_token() xml = am.get_products_by_dispensary(token, '684') # write xml string in latest.xml f = open('latest.xml', 'w') f.write('%s' % xml) f.close() except Exception as exp: print('system_update() :: Got exp: %s' % exp) flog('system update failed') return 'api key: % s' % key
def get_not_trendings(csv_file, region='GB', limit=10, limit_trendings=None): # Get trendings to find date range trendings, trending_ids = get_trendings(csv_file) found_videos = [] i = 0 with ApiManager() as manager: for trending_key, trending_value in trendings.items(): videos = manager.search_videos(trending_value.get_latest_video(), trending_value.get_oldest_video(), region, limit) found_videos = found_videos + videos i += 1 if limit_trendings and i > limit_trendings: break # Remove videos, that are on "trending" list ids = [video.video_id for video in found_videos if video.video_id not in trending_ids] # Remove duplicates ids = list(set(ids)) not_trendings = manager.get_videos(ids) return not_trendings
from api_manager import ApiManager from exceptions import * InlineKeyboard = types.inline_keyboard.InlineKeyboardMarkup InlineButton = types.inline_keyboard.InlineKeyboardButton RemoveKeyboard = types.ReplyKeyboardRemove ReplyKeyboard = types.ReplyKeyboardMarkup ReplyButton = types.KeyboardButton TOKEN = '699496323:AAHpHRNraSsW_DdZh4jNV518WDGglZKLaJY' storage = MemoryStorage() bot = Bot(TOKEN, parse_mode='Markdown', ) dp = Dispatcher(bot, storage=storage) api = ApiManager() class AuthForm(StatesGroup): login = State() password = State() def start_filter(msg): return msg.chat.type == 'private' and msg.text == '/start' def menu_btn(): btn = ReplyKeyboard(resize_keyboard=True) btn.insert('👤 Профиль') return btn
from bottle import route, post, request, hook, template, static_file from instagram import client, subscriptions from config import CONFIG, unauthenticated_api from my_thread import MyThread bottle.debug(True) session_opts = { 'session.type': 'file', 'session.data_dir': './session/', 'session.auto': True, } app = beaker.middleware.SessionMiddleware(bottle.app(), session_opts) pic_manager = PicManager() api_manager = ApiManager() @hook('before_request') def setup_request(): request.session = request.environ['beaker.session'] def process_tag_update(update): print(update) @route('/static/<filepath:path>') def server_static(filepath): return static_file(filepath, root='./static')