aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJinwei Zhao <[email protected]>2017-01-31 19:07:43 +0800
committerJinwei Zhao <[email protected]>2017-02-01 21:41:54 +0800
commit88750f859acf7e91d1f6403f89baa54189f51cbd (patch)
treea672fa366cae1e0890e9856f784d4c08ca67529a
parentdf17a8695cba8f643593664f383912951e234540 (diff)
downloadCOMM2TG-88750f859acf7e91d1f6403f89baa54189f51cbd.tar.gz
write lat lng to config file
-rwxr-xr-xasync_bot.py34
-rwxr-xr-xconfig.json.example6
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
5import time 5import time
6import json 6import json
7import logging 7import logging
8import urllib 8import inspect
9import sys 9import sys
10from selenium import webdriver 10from selenium import webdriver
11 11
@@ -31,7 +31,10 @@ DBHost = ''
31BlockList = '' 31BlockList = ''
32LOG_FILENAME = 'voh.log' 32LOG_FILENAME = 'voh.log'
33TIME_ZONE='Asia/Shanghai' 33TIME_ZONE='Asia/Shanghai'
34 34minLngE6 = 0
35minLatE6 = 0
36maxLngE6 = 0
37maxLatE6 = 0
35 38
36class CookieException(Exception): 39class 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):
174def main(): 186def 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}
Powered by cgit v1.2.3 (git 2.41.0)