def start_vk(): for event in longpoll.listen(): if event.type == VkEventType.MESSAGE_NEW and event.to_me: user_res=vk_session.method("users.get",{'user_ids':[event.user_id],'fields':['id','first_name','last_name']}) insert_user(user_res[0]['id'],user_res[0]['first_name'],user_res[0]['last_name'],'vk') result = vk_session.method("messages.getById", {"message_ids": [event.message_id],"group_id": 192738048}) if result['items'][0]['geo']: geo = result['items'][0]['geo']['coordinates'] latitude, longitude = geo['latitude'], geo['longitude'] print(latitude, longitude) my_location={'latitude':latitude,'longitude':longitude} places = select_places() dist={p['id']:distance(my_location['longitude'],my_location['latitude'],p['loc_lon'],p['loc_lat']) for p in places} min_dist=min(dist.keys(), key=(lambda k: dist[k])) db_place = select_place_param(min_dist) image_url = 'https://ecoukhta.herokuapp.com/images/?img='+str(db_place['id']) image = session.get(image_url, stream=True) photo = upload.photo_messages(photos=image.raw)[0] attachments='photo{}_{}'.format(photo['owner_id'], photo['id']) vk.messages.send( user_id=event.user_id, attachment=attachments, random_id=get_random_id(), lat=db_place['loc_lat'], long=db_place['loc_lon'], message=db_place['info'] ) insert_log(select_userid_by_name(str(user_res[0]['id'])),db_place['id']) return 'ok' else: return 'ok'
def handle_datagram(self,data, address): try: name,pt = decode_protocol(data) insert_log(name,pt.lng,pt.lat) # cars[name] = pt except Exception as e: print "error",e,data
def record_position(self,data): try: name,pt = decode_protocol(data) insert_log(name,pt.lng,pt.lat) # cars[name] = pt except Exception as e: print "error",e,data self.stream.write("M") self.read_message()
def list_message(message): user=str(message.from_user.id) insert_user(user,message.from_user.first_name, message.from_user.last_name,'telegram') places= select_places() #red_get(str(message.from_user.id)+'_type')) for p in places: db_place = select_place_param(p['id']) bot.send_location(message.chat.id, db_place['loc_lat'], db_place['loc_lon']) bot.send_photo(message.chat.id, db_place['photo'],caption=db_place['info']) insert_log(select_userid_by_name(str(message.from_user.id)),1)
def loc_message(message): user=str(message.from_user.id) insert_user(user,message.from_user.first_name, message.from_user.last_name,'telegram') my_location={'latitude':message.location.latitude,'longitude':message.location.longitude} places = select_places() #red_get(str(message.from_user.id)+'_type')) dist={p['id']:distance(my_location['longitude'],my_location['latitude'],p['loc_lon'],p['loc_lat']) for p in places} min_dist=min(dist.keys(), key=(lambda k: dist[k])) db_place = select_place_param(min_dist) bot.send_location(message.chat.id, db_place['loc_lat'], db_place['loc_lon']) bot.send_photo(message.chat.id, db_place['photo'],caption=db_place['info']) insert_log(select_userid_by_name(str(message.from_user.id)),db_place['id'])
proxy = get_proxy(last_proxy) last_proxy = proxy['http'] if PY_ENV == 'production': # config.browser_user_agent = UserAgent().random config.browser_user_agent = 'Tutubot/1.0' # config.proxies = proxy try: source = newspaper.build(url, config=config) except Exception as e: if PY_ENV == 'development': print('(SOURCE ERROR) Source Skipped\n') insert_log(source_id, 'sourceCrawl', 'error', float(time.clock() - src_start_time), { 'errorMessage': 'SOURCE ERROR', 'crawlerName': 'credible crawler' }) continue error_articles = [] prev_uuid = '' for article in source.articles: url_uuid = get_uuid(clean_url(article.url)) article.id = url_uuid if prev_uuid == url_uuid: continue if get_one(url_uuid, 'errorArticles') or get_one( url_uuid, 'articles'):