aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'async_bot.py')
-rwxr-xr-xasync_bot.py19
1 files changed, 8 insertions, 11 deletions
diff --git a/async_bot.py b/async_bot.py
index 668e0fe..51a347c 100755
--- a/async_bot.py
+++ b/async_bot.py
@@ -6,6 +6,7 @@ import time
6import json 6import json
7import logging 7import logging
8import inspect 8import inspect
9import urllib
9import sys 10import sys
10from selenium import webdriver 11from selenium import webdriver
11 12
@@ -36,7 +37,9 @@ minLatE6 = 0
36maxLngE6 = 0 37maxLngE6 = 0
37maxLatE6 = 0 38maxLatE6 = 0
38 39
40
39class CookieException(Exception): 41class CookieException(Exception):
42 """Intel Error"""
40 pass 43 pass
41 44
42 45
@@ -83,7 +86,6 @@ def read_config():
83 86
84 logging.basicConfig(level=logging.DEBUG, 87 logging.basicConfig(level=logging.DEBUG,
85 filename=LOG_FILENAME, 88 filename=LOG_FILENAME,
86 encoding='utf8',
87 filemode='w') 89 filemode='w')
88 console = logging.StreamHandler() 90 console = logging.StreamHandler()
89 console.setLevel(logging.INFO) 91 console.setLevel(logging.INFO)
@@ -147,6 +149,7 @@ def send_message(bot, message, monitor=False):
147 if monitor is True: 149 if monitor is True:
148 bot.sendMessage(chat_id="@voamonitor", text=message) 150 bot.sendMessage(chat_id="@voamonitor", text=message)
149 else: 151 else:
152 print(type(message))
150 bot.sendMessage(chat_id=CHANNEL_NAME, text=message) 153 bot.sendMessage(chat_id=CHANNEL_NAME, text=message)
151 logger.info(get_time() + ": sendMsg " + message) 154 logger.info(get_time() + ": sendMsg " + message)
152 break 155 break
@@ -184,6 +187,7 @@ def insert_message_to_database(time, id, msg):
184 187
185 188
186def main(): 189def main():
190 # global intel
187 logger = logging.getLogger('main') 191 logger = logging.getLogger('main')
188 192
189 # Lat & Lng of fetch region 193 # Lat & Lng of fetch region
@@ -211,15 +215,16 @@ def main():
211 logger.error(get_time() + ": Unexpected error: " + str(sys.exc_info()[0]) + " " + str(inspect.currentframe().f_lineno)) 215 logger.error(get_time() + ": Unexpected error: " + str(sys.exc_info()[0]) + " " + str(inspect.currentframe().f_lineno))
212 time.sleep(3) 216 time.sleep(3)
213 217
218
214 # fetch message 219 # fetch message
215 count = 0 220 count = 0
216 while True: 221 while True:
217 count += 1 222 count += 1
223 logger.info(get_time() + ": {} Fetching from Intel...".format(str(count)))
218 224
219 with open('cookie') as cookies: 225 with open('cookie') as cookies:
220 cookies = cookies.read().strip() 226 cookies = cookies.read().strip()
221 logger.info(get_time() + ": {} Fetching from Intel...".format(str(count))) 227
222
223 # fetch message per time 228 # fetch message per time
224 while True: 229 while True:
225 try: 230 try:
@@ -228,13 +233,6 @@ def main():
228 if result: 233 if result:
229 mints = result[0][1] + 1 234 mints = result[0][1] + 1
230 break 235 break
231 except CookieException:
232 while True:
233 try:
234 if fetch_cookie():
235 break
236 except CookieException:
237 time.sleep(3)
238 except Exception: 236 except Exception:
239 logger.error(get_time() + ": Unexpected error: " + str(sys.exc_info()[0]) + " " + str(inspect.currentframe().f_lineno)) 237 logger.error(get_time() + ": Unexpected error: " + str(sys.exc_info()[0]) + " " + str(inspect.currentframe().f_lineno))
240 time.sleep(3) 238 time.sleep(3)
@@ -248,7 +246,6 @@ def main():
248 246
249 message = ingrex.Message(item) 247 message = ingrex.Message(item)
250 if message.ptype == 'PLAYER_GENERATED': 248 if message.ptype == 'PLAYER_GENERATED':
251 logger.info(get_time() + " " + message.msg)
252 if find_message_record(message.guid) is False: 249 if find_message_record(message.guid) is False:
253 insert_message_to_database(message.time, message.guid, message.msg) 250 insert_message_to_database(message.time, message.guid, message.msg)
254 send_message(bot, message.msg, False) 251 send_message(bot, message.msg, False)
Powered by cgit v1.2.3 (git 2.41.0)