diff options
-rwxr-xr-x | async_bot.py | 34 | ||||
-rwxr-xr-x | config.json.example | 6 |
2 files changed, 28 insertions, 12 deletions
diff --git a/async_bot.py b/async_bot.py index 5f33f7e..668e0fe 100755 --- a/async_bot.py +++ b/async_bot.py | |||
@@ -5,7 +5,7 @@ import re | |||
5 | import time | 5 | import time |
6 | import json | 6 | import json |
7 | import logging | 7 | import logging |
8 | import urllib | 8 | import inspect |
9 | import sys | 9 | import sys |
10 | from selenium import webdriver | 10 | from selenium import webdriver |
11 | 11 | ||
@@ -31,7 +31,10 @@ DBHost = '' | |||
31 | BlockList = '' | 31 | BlockList = '' |
32 | LOG_FILENAME = 'voh.log' | 32 | LOG_FILENAME = 'voh.log' |
33 | TIME_ZONE='Asia/Shanghai' | 33 | TIME_ZONE='Asia/Shanghai' |
34 | 34 | minLngE6 = 0 | |
35 | minLatE6 = 0 | ||
36 | maxLngE6 = 0 | ||
37 | maxLatE6 = 0 | ||
35 | 38 | ||
36 | class CookieException(Exception): | 39 | class CookieException(Exception): |
37 | pass | 40 | pass |
@@ -53,6 +56,10 @@ def read_config(): | |||
53 | global DBHost | 56 | global DBHost |
54 | global BlockList | 57 | global BlockList |
55 | global LOG_FILENAME | 58 | global LOG_FILENAME |
59 | global minLngE6 | ||
60 | global minLatE6 | ||
61 | global maxLngE6 | ||
62 | global maxLatE6 | ||
56 | 63 | ||
57 | configfile = open("./config.json") | 64 | configfile = open("./config.json") |
58 | config = json.load(configfile) | 65 | config = json.load(configfile) |
@@ -66,12 +73,17 @@ def read_config(): | |||
66 | DBPass = config["DBPass"] | 73 | DBPass = config["DBPass"] |
67 | DBHost = config["DBHost"] | 74 | DBHost = config["DBHost"] |
68 | BlockList = config["BlockList"] | 75 | BlockList = config["BlockList"] |
76 | minLngE6 = config["minLngE6"] | ||
77 | minLatE6 = config["minLatE6"] | ||
78 | maxLngE6 = config["maxLngE6"] | ||
79 | maxLatE6 = config["maxLatE6"] | ||
69 | 80 | ||
70 | os.environ['TZ'] = TIME_ZONE | 81 | os.environ['TZ'] = TIME_ZONE |
71 | time.tzset() | 82 | time.tzset() |
72 | 83 | ||
73 | logging.basicConfig(level=logging.DEBUG, | 84 | logging.basicConfig(level=logging.DEBUG, |
74 | filename=LOG_FILENAME, | 85 | filename=LOG_FILENAME, |
86 | encoding='utf8', | ||
75 | filemode='w') | 87 | filemode='w') |
76 | console = logging.StreamHandler() | 88 | console = logging.StreamHandler() |
77 | console.setLevel(logging.INFO) | 89 | console.setLevel(logging.INFO) |
@@ -142,7 +154,7 @@ def send_message(bot, message, monitor=False): | |||
142 | logger.error(get_time() + ": Send Message to Channel Failed") | 154 | logger.error(get_time() + ": Send Message to Channel Failed") |
143 | time.sleep(1) | 155 | time.sleep(1) |
144 | except Exception: | 156 | except Exception: |
145 | logger.error(get_time() + ": Unexpected error: " + str(sys.exc_info()[0])) | 157 | logger.error(get_time() + ": Unexpected error: " + str(sys.exc_info()[0]) + " " + str(inspect.currentframe().f_lineno)) |
146 | time.sleep(1) | 158 | time.sleep(1) |
147 | 159 | ||
148 | 160 | ||
@@ -174,12 +186,12 @@ def insert_message_to_database(time, id, msg): | |||
174 | def main(): | 186 | def main(): |
175 | logger = logging.getLogger('main') | 187 | logger = logging.getLogger('main') |
176 | 188 | ||
177 | # Lat Lng of Hangzhou | 189 | # Lat & Lng of fetch region |
178 | field = { | 190 | field = { |
179 | 'minLngE6': 119618783, | 191 | 'minLngE6': minLngE6, |
180 | 'minLatE6': 29912919, | 192 | 'minLatE6': minLatE6, |
181 | 'maxLngE6': 121018722, | 193 | 'maxLngE6': maxLngE6, |
182 | 'maxLatE6': 30573739, | 194 | 'maxLatE6': maxLatE6, |
183 | } | 195 | } |
184 | 196 | ||
185 | mints = -1 | 197 | mints = -1 |
@@ -196,7 +208,7 @@ def main(): | |||
196 | logger.error(get_time() + ': Fetch Cookie Failed') | 208 | logger.error(get_time() + ': Fetch Cookie Failed') |
197 | time.sleep(3) | 209 | time.sleep(3) |
198 | except Exception: | 210 | except Exception: |
199 | logger.error(get_time() + ": Unexpected error: " + str(sys.exc_info()[0])) | 211 | logger.error(get_time() + ": Unexpected error: " + str(sys.exc_info()[0]) + " " + str(inspect.currentframe().f_lineno)) |
200 | time.sleep(3) | 212 | time.sleep(3) |
201 | 213 | ||
202 | # fetch message | 214 | # fetch message |
@@ -224,7 +236,7 @@ def main(): | |||
224 | except CookieException: | 236 | except CookieException: |
225 | time.sleep(3) | 237 | time.sleep(3) |
226 | except Exception: | 238 | except Exception: |
227 | logger.error(get_time() + ": Unexpected error: " + str(sys.exc_info()[0])) | 239 | logger.error(get_time() + ": Unexpected error: " + str(sys.exc_info()[0]) + " " + str(inspect.currentframe().f_lineno)) |
228 | time.sleep(3) | 240 | time.sleep(3) |
229 | 241 | ||
230 | for item in result[::-1]: | 242 | for item in result[::-1]: |
@@ -251,5 +263,5 @@ if __name__ == '__main__': | |||
251 | try: | 263 | try: |
252 | main() | 264 | main() |
253 | except Exception: | 265 | except Exception: |
254 | send_message(bot, 'Main Unexpected error' + str(sys.exc_info()[0]), True) | 266 | send_message(bot, 'Main Unexpected error' + str(sys.exc_info()[0]) + " " + str(inspect.currentframe().f_lineno), True) |
255 | time.sleep(3) \ No newline at end of file | 267 | time.sleep(3) \ No newline at end of file |
diff --git a/config.json.example b/config.json.example index ea29c95..8679741 100755 --- a/config.json.example +++ b/config.json.example | |||
@@ -8,5 +8,9 @@ | |||
8 | "DBUser": "", | 8 | "DBUser": "", |
9 | "DBPass": "", | 9 | "DBPass": "", |
10 | "DBHost": "ip:port", | 10 | "DBHost": "ip:port", |
11 | "BlockList": "" | 11 | "BlockList": "", |
12 | "minLngE6": 119618783, | ||
13 | "minLatE6": 29912919, | ||
14 | "maxLngE6": 121018722, | ||
15 | "maxLatE6": 30573739 | ||
12 | } | 16 | } |