async def db(): global tokens_file, ads ads = AsyncIOMotorClient()['divar']['ads'] ads.create_index([('token', 1)]) try: with open('tokens', 'r+') as tf: remain_tokens = set( [line.strip() for line in tf.readlines() if line.strip()]) # remain_tokens.remove('') if '' in remain_tokens else None tf.truncate(0) except FileNotFoundError: remain_tokens = set() db_tokens = await ads.find({}, {'token': 1}).to_list(None) db_tokens = set([doc['token'] for doc in db_tokens]) tokens.extend(list(remain_tokens - db_tokens)) tokens_file = open('tokens', 'a+') for token in tokens: tokens_file.write(f'{token}\n')
async def init(sanic, _loop): global session, locations, users, paths, contacts, fcm, loop loop = _loop fcm = FCM('197435492753', 'AAAALfgSiZE:APA91bHfj1dHgC_KR7ehPTQCrdXo10Js1vWiWwmcAhvMELNcb7_926MB6zHuyIJGO8PgNnkhVuZwNf9chdkgF2xkX3pY3Y9rmSTM6Fxcwpn6f5RySAYQpWGSxx_Pg1H996atVd0VJ9Hk') session = await aiohttp.ClientSession(connector=aiohttp.TCPConnector(verify_ssl=False)).__aenter__() db = AsyncIOMotorClient().express locations = AsyncIOMotorClient('mongodb://localhost:27020').express.locations locations.create_index([('location', '2d')]) locations.create_index([('location', '2dsphere')]) locations.create_index([('_date', 1)]) locations.create_index([('hang', 1), ('user', 1), ('_date', 1)]) users = db.users users.create_index([('user', pymongo.DESCENDING), ('hang', pymongo.DESCENDING)], unique=True) paths = db.paths paths.create_index([('hang', 1), ('porters.ack', 1)]) paths.create_index([('hang', 1)], partialFilterExpression = {'porters': []}) contacts = db.contacts contacts.create_index([('address', 'text')]) contacts.create_index([('user', 1), ('hang', 1)]) # model.load_weights('eta.h5py') while True: if not cnt_lock.value: global mu cnt_lock.value = True # rx, ty = star[cnt.value][0][0], star[cnt.value][1][1] # ty = ty.send() # mu = Client(await rx.open(loop), await ty.__enter__().open()) # from client.simulator.v05 import sims_star # sims_rx, sims_ty = sims_star[cnt.value][0][0], sims_star[cnt.value][1][1] # sims = (await sims_rx.open(loop), await sims_ty.send().__enter__().open()) cnt.value += 1 cnt_lock.value = False break