diff options
Diffstat (limited to 'bot.py')
-rwxr-xr-x | bot.py | 34 |
1 files changed, 19 insertions, 15 deletions
@@ -28,8 +28,8 @@ DBHost = '' | |||
28 | BlockList = '' | 28 | BlockList = '' |
29 | 29 | ||
30 | LOG_FILENAME = 'voh.log' | 30 | LOG_FILENAME = 'voh.log' |
31 | logging.basicConfig(level = logging.DEBUG, | 31 | logging.basicConfig(level=logging.DEBUG, |
32 | filename = LOG_FILENAME, | 32 | filename=LOG_FILENAME, |
33 | filemode='w') | 33 | filemode='w') |
34 | console = logging.StreamHandler() | 34 | console = logging.StreamHandler() |
35 | console.setLevel(logging.INFO) | 35 | console.setLevel(logging.INFO) |
@@ -77,6 +77,7 @@ def readConfig(): | |||
77 | os.environ['TZ'] = 'Asia/Shanghai' | 77 | os.environ['TZ'] = 'Asia/Shanghai' |
78 | time.tzset() | 78 | time.tzset() |
79 | 79 | ||
80 | |||
80 | def fetchCookie(): | 81 | def fetchCookie(): |
81 | global Debug | 82 | global Debug |
82 | global Email | 83 | global Email |
@@ -149,7 +150,7 @@ def sendMessge(bot, msg): | |||
149 | req = urllib.request.Request(url, headers={'Content-Type': 'application/x-www-form-urlencoded'}) | 150 | req = urllib.request.Request(url, headers={'Content-Type': 'application/x-www-form-urlencoded'}) |
150 | resp = urllib.request.urlopen(req) | 151 | resp = urllib.request.urlopen(req) |
151 | data = resp.read() | 152 | data = resp.read() |
152 | 153 | logger.info(data) | |
153 | logger.info(getTime() + ": sendMsg " + msg) | 154 | logger.info(getTime() + ": sendMsg " + msg) |
154 | break | 155 | break |
155 | except NetworkError: | 156 | except NetworkError: |
@@ -176,7 +177,6 @@ def formatMessage(raw): | |||
176 | msg = '' | 177 | msg = '' |
177 | plext = raw[2]['plext'] | 178 | plext = raw[2]['plext'] |
178 | markup = plext['markup'] | 179 | markup = plext['markup'] |
179 | #plaintext = plext['text'] | ||
180 | 180 | ||
181 | for mark in markup: | 181 | for mark in markup: |
182 | if mark[0] == 'SECURE': | 182 | if mark[0] == 'SECURE': |
@@ -219,6 +219,7 @@ def formatMessage(raw): | |||
219 | 219 | ||
220 | return msg | 220 | return msg |
221 | 221 | ||
222 | |||
222 | def FindRecord(id): | 223 | def FindRecord(id): |
223 | uri = 'mongodb://' + DBHost | 224 | uri = 'mongodb://' + DBHost |
224 | Conn = MongoClient(uri) | 225 | Conn = MongoClient(uri) |
@@ -242,14 +243,15 @@ def insertDB(time, id, msg): | |||
242 | mycollection.insert(post) | 243 | mycollection.insert(post) |
243 | Conn.close() | 244 | Conn.close() |
244 | 245 | ||
246 | |||
245 | def main(): | 247 | def main(): |
246 | logger = logging.getLogger('main') | 248 | logger = logging.getLogger('main') |
247 | 249 | ||
248 | field = { | 250 | field = { |
249 | 'minLngE6':119618783, | 251 | 'minLngE6': 119618783, |
250 | 'minLatE6':29912919, | 252 | 'minLatE6': 29912919, |
251 | 'maxLngE6':121018722, | 253 | 'maxLngE6': 121018722, |
252 | 'maxLatE6':30573739, | 254 | 'maxLatE6': 30573739, |
253 | } | 255 | } |
254 | 256 | ||
255 | mints = -1 | 257 | mints = -1 |
@@ -259,7 +261,7 @@ def main(): | |||
259 | 261 | ||
260 | while True: | 262 | while True: |
261 | try: | 263 | try: |
262 | if fetchCookie(): | 264 | if fetchCookie(): |
263 | break | 265 | break |
264 | except CookieException: | 266 | except CookieException: |
265 | time.sleep(3) | 267 | time.sleep(3) |
@@ -290,25 +292,27 @@ def main(): | |||
290 | break | 292 | break |
291 | except CookieException: | 293 | except CookieException: |
292 | time.sleep(3) | 294 | time.sleep(3) |
295 | except Exception: | ||
296 | pass | ||
293 | 297 | ||
294 | for item in result[::-1]: | 298 | for item in result[::-1]: |
295 | message = ingrex.Message(item) | 299 | message = ingrex.Message(item) |
296 | 300 | ||
297 | if message.ptype == 'PLAYER_GENERATED': | 301 | if message.ptype == 'PLAYER_GENERATED': |
298 | logger.info(getTime() + str(item)) | 302 | # logger.info(getTime() + str(item)) |
299 | 303 | ||
300 | msg = formatMessage(item) | 304 | msg = formatMessage(item) |
301 | if msg == 'Blocked': | 305 | if msg == 'Blocked': |
302 | logger.info(getTime() + " " + message.text) | 306 | logger.info(getTime() + " " + message.text) |
303 | else: | 307 | else: |
304 | msg = message.time + " " + msg | 308 | msg = message.time + " " + msg |
305 | logger.info(getTime() + " " + msg) | 309 | # logger.info(getTime() + " " + msg) |
306 | if FindRecord(message.guid) == False: | 310 | if FindRecord(message.guid) is False: |
307 | insertDB(message.time, message.guid, msg) | 311 | insertDB(message.time, message.guid, msg) |
308 | sendMonitor(bot, msg) | 312 | # sendMonitor(bot, msg) |
309 | #sendMessge(bot, msg) | 313 | sendMessge(bot, msg) |
310 | 314 | ||
311 | time.sleep(5) | 315 | time.sleep(10) |
312 | 316 | ||
313 | if __name__ == '__main__': | 317 | if __name__ == '__main__': |
314 | readConfig() | 318 | readConfig() |