aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbot.py34
-rwxr-xr-xconfig.json.example10
-rwxr-xr-xingrex/intel.py6
-rwxr-xr-xingrex/praser.py1
-rwxr-xr-xingrex/utils.py19
-rw-r--r--searchbot.py11
6 files changed, 52 insertions, 29 deletions
diff --git a/bot.py b/bot.py
index a521764..dc50264 100755
--- a/bot.py
+++ b/bot.py
@@ -28,8 +28,8 @@ DBHost = ''
28BlockList = '' 28BlockList = ''
29 29
30LOG_FILENAME = 'voh.log' 30LOG_FILENAME = 'voh.log'
31logging.basicConfig(level = logging.DEBUG, 31logging.basicConfig(level=logging.DEBUG,
32 filename = LOG_FILENAME, 32 filename=LOG_FILENAME,
33 filemode='w') 33 filemode='w')
34console = logging.StreamHandler() 34console = logging.StreamHandler()
35console.setLevel(logging.INFO) 35console.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
80def fetchCookie(): 81def 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
222def FindRecord(id): 223def 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
245def main(): 247def 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
313if __name__ == '__main__': 317if __name__ == '__main__':
314 readConfig() 318 readConfig()
diff --git a/config.json.example b/config.json.example
index 8d9b824..7e61d75 100755
--- a/config.json.example
+++ b/config.json.example
@@ -1,9 +1,9 @@
1{ 1{
2 "Email": "Your Ingress Account Email", 2 "Email": "Your Ingress Account Email",
3 "Passwd": "Your Ingress Account Password", 3 "Passwd": "Your Ingress Account Password",
4 "BOT_TOKEN": "Your Telegram Bot Token", 4 "BOT_TOKEN": "Your Telegram Bot Token",
5 "CHANNEL_NAME": "Your Channel ID", 5 "CHANNEL_NAME": "Your Channel ID",
6 "PhantomjsPath": "/usr/local/phantomjs/bin/phantomjs", 6 "PhantomjsPath": "/usr/local/phantomjs/bin/phantomjs",
7 "DBName": "", 7 "DBName": "",
8 "DBUser": "", 8 "DBUser": "",
9 "DBPass": "", 9 "DBPass": "",
diff --git a/ingrex/intel.py b/ingrex/intel.py
index f13b2a2..506c6bc 100755
--- a/ingrex/intel.py
+++ b/ingrex/intel.py
@@ -2,7 +2,7 @@
2import requests 2import requests
3import re 3import re
4import json 4import json
5import os 5
6 6
7class Intel(object): 7class Intel(object):
8 "main class with all Intel functions" 8 "main class with all Intel functions"
@@ -43,7 +43,7 @@ class Intel(object):
43 count = 0 43 count = 0
44 while count < 3: 44 while count < 3:
45 try: 45 try:
46 request = self.session.post(url, data=json.dumps(payload), headers=self.headers) 46 request = self.session.post(url, data=json.dumps(payload), headers=self.headers, timeout=600)
47 return request.json()['result'] 47 return request.json()['result']
48 except requests.ConnectionError: 48 except requests.ConnectionError:
49 raise IntelError 49 raise IntelError
@@ -132,10 +132,12 @@ class Intel(object):
132 } 132 }
133 return self.fetch(url, payload) 133 return self.fetch(url, payload)
134 134
135
135class IntelError(BaseException): 136class IntelError(BaseException):
136 """Intel Error""" 137 """Intel Error"""
137 pass 138 pass
138 139
140
139class CookieError(IntelError): 141class CookieError(IntelError):
140 """Intel Error""" 142 """Intel Error"""
141 pass 143 pass
diff --git a/ingrex/praser.py b/ingrex/praser.py
index 732ab1b..a05ec1e 100755
--- a/ingrex/praser.py
+++ b/ingrex/praser.py
@@ -9,6 +9,7 @@ if osname == "Linux":
9 os.environ['TZ'] = 'Asia/Shanghai' 9 os.environ['TZ'] = 'Asia/Shanghai'
10 time.tzset() 10 time.tzset()
11 11
12
12class Message(object): 13class Message(object):
13 "Message object" 14 "Message object"
14 def __init__(self, raw_msg): 15 def __init__(self, raw_msg):
diff --git a/ingrex/utils.py b/ingrex/utils.py
index 8090f15..17d69e6 100755
--- a/ingrex/utils.py
+++ b/ingrex/utils.py
@@ -1,14 +1,16 @@
1"Map Utils" 1"Map Utils"
2from math import pi, sin, cos, tan, asin, radians, sqrt, log 2from math import pi, sin, cos, tan, asin, radians, sqrt, log
3 3
4
4def calc_tile(lng, lat, zoomlevel): 5def calc_tile(lng, lat, zoomlevel):
5 tilecounts = [1,1,1,40,40,80,80,320,1E3,2E3,2E3,4E3,8E3,16E3,16E3,32E3] 6 tilecounts = [1, 1, 1, 40, 40, 80, 80, 320, 1E3, 2E3, 2E3, 4E3, 8E3, 16E3, 16E3, 32E3]
6 rlat = radians(lat) 7 rlat = radians(lat)
7 tilecount = tilecounts[zoomlevel] 8 tilecount = tilecounts[zoomlevel]
8 xtile = int((lng + 180.0) / 360.0 * tilecount) 9 xtile = int((lng + 180.0) / 360.0 * tilecount)
9 ytile = int((1.0 - log(tan(rlat) + (1 / cos(rlat))) / pi) / 2.0 * tilecount) 10 ytile = int((1.0 - log(tan(rlat) + (1 / cos(rlat))) / pi) / 2.0 * tilecount)
10 return xtile, ytile 11 return xtile, ytile
11 12
13
12def calc_dist(lat1, lng1, lat2, lng2): 14def calc_dist(lat1, lng1, lat2, lng2):
13 lat1, lng1, lat2, lng2 = map(radians, [lat1, lng1, lat2, lng2]) 15 lat1, lng1, lat2, lng2 = map(radians, [lat1, lng1, lat2, lng2])
14 dlat = lat1 - lat2 16 dlat = lat1 - lat2
@@ -18,12 +20,13 @@ def calc_dist(lat1, lng1, lat2, lng2):
18 m = 6367.0 * c * 1000 20 m = 6367.0 * c * 1000
19 return m 21 return m
20 22
23
21def point_in_poly(x, y, poly): 24def point_in_poly(x, y, poly):
22 n = len(poly) 25 n = len(poly)
23 inside = False 26 inside = False
24 p1x,p1y = poly[0] 27 p1x, p1y = poly[0]
25 for i in range(n+1): 28 for i in range(n+1):
26 p2x,p2y = poly[i % n] 29 p2x, p2y = poly[i % n]
27 if y > min(p1y, p2y): 30 if y > min(p1y, p2y):
28 if y <= max(p1y, p2y): 31 if y <= max(p1y, p2y):
29 if x <= max(p1x, p2x): 32 if x <= max(p1x, p2x):
@@ -31,9 +34,10 @@ def point_in_poly(x, y, poly):
31 xints = (y - p1y) * (p2x - p1x) / (p2y - p1y) + p1x 34 xints = (y - p1y) * (p2x - p1x) / (p2y - p1y) + p1x
32 if p1x == p2x or x <= xints: 35 if p1x == p2x or x <= xints:
33 inside = not inside 36 inside = not inside
34 p1x,p1y = p2x,p2y 37 p1x, p1y = p2x, p2y
35 return inside 38 return inside
36 39
40
37def transform(wgLat, wgLon): 41def transform(wgLat, wgLon):
38 """ 42 """
39 transform(latitude,longitude) , WGS84 43 transform(latitude,longitude) , WGS84
@@ -44,7 +48,7 @@ def transform(wgLat, wgLon):
44 if (outOfChina(wgLat, wgLon)): 48 if (outOfChina(wgLat, wgLon)):
45 mgLat = wgLat 49 mgLat = wgLat
46 mgLon = wgLon 50 mgLon = wgLon
47 return mgLat,mgLon 51 return mgLat, mgLon
48 dLat = transformLat(wgLon - 105.0, wgLat - 35.0) 52 dLat = transformLat(wgLon - 105.0, wgLat - 35.0)
49 dLon = transformLon(wgLon - 105.0, wgLat - 35.0) 53 dLon = transformLon(wgLon - 105.0, wgLat - 35.0)
50 radLat = wgLat / 180.0 * pi 54 radLat = wgLat / 180.0 * pi
@@ -55,7 +59,8 @@ def transform(wgLat, wgLon):
55 dLon = (dLon * 180.0) / (a / sqrtMagic * cos(radLat) * pi) 59 dLon = (dLon * 180.0) / (a / sqrtMagic * cos(radLat) * pi)
56 mgLat = wgLat + dLat 60 mgLat = wgLat + dLat
57 mgLon = wgLon + dLon 61 mgLon = wgLon + dLon
58 return mgLat,mgLon 62 return mgLat, mgLon
63
59 64
60def outOfChina(lat, lon): 65def outOfChina(lat, lon):
61 if (lon < 72.004 or lon > 137.8347): 66 if (lon < 72.004 or lon > 137.8347):
@@ -64,6 +69,7 @@ def outOfChina(lat, lon):
64 return True 69 return True
65 return False 70 return False
66 71
72
67def transformLat(x, y): 73def transformLat(x, y):
68 ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * sqrt(abs(x)) 74 ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * sqrt(abs(x))
69 ret += (20.0 * sin(6.0 * x * pi) + 20.0 * sin(2.0 * x * pi)) * 2.0 / 3.0 75 ret += (20.0 * sin(6.0 * x * pi) + 20.0 * sin(2.0 * x * pi)) * 2.0 / 3.0
@@ -71,6 +77,7 @@ def transformLat(x, y):
71 ret += (160.0 * sin(y / 12.0 * pi) + 320 * sin(y * pi / 30.0)) * 2.0 / 3.0 77 ret += (160.0 * sin(y / 12.0 * pi) + 320 * sin(y * pi / 30.0)) * 2.0 / 3.0
72 return ret 78 return ret
73 79
80
74def transformLon(x, y): 81def transformLon(x, y):
75 ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * sqrt(abs(x)) 82 ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * sqrt(abs(x))
76 ret += (20.0 * sin(6.0 * x * pi) + 20.0 * sin(2.0 * x * pi)) * 2.0 / 3.0 83 ret += (20.0 * sin(6.0 * x * pi) + 20.0 * sin(2.0 * x * pi)) * 2.0 / 3.0
diff --git a/searchbot.py b/searchbot.py
index e18875f..ee504d5 100644
--- a/searchbot.py
+++ b/searchbot.py
@@ -3,8 +3,10 @@ from telegram.ext import Updater, CommandHandler
3import logging 3import logging
4# Enable logging 4# Enable logging
5logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', 5logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
6 level=logging.DEBUG) 6 level=logging.DEBUG)
7logger = logging.getLogger(__name__) 7logger = logging.getLogger(__name__)
8
9
8def search(bot, update, args): 10def search(bot, update, args):
9 agentid = args[0] 11 agentid = args[0]
10 print(agentid) 12 print(agentid)
@@ -15,10 +17,16 @@ def search(bot, update, args):
15 for i in res: 17 for i in res:
16 print(i) 18 print(i)
17 bot.sendMessage(update.message.chat_id, text=str(i)) 19 bot.sendMessage(update.message.chat_id, text=str(i))
20
21
18def start(bot, update): 22def start(bot, update):
19 bot.sendMessage(update.message.chat_id, text="Hi! Use /search agentid to start, no need for @") 23 bot.sendMessage(update.message.chat_id, text="Hi! Use /search agentid to start, no need for @")
24
25
20def error(bot, update, error): 26def error(bot, update, error):
21 logger.warn('Update "%s" caused error "%s"' % (update, error)) 27 logger.warn('Update "%s" caused error "%s"' % (update, error))
28
29
22def main(): 30def main():
23 updater = Updater('Telegram Bot ID') 31 updater = Updater('Telegram Bot ID')
24 dp = updater.dispatcher 32 dp = updater.dispatcher
@@ -28,5 +36,6 @@ def main():
28 dp.add_error_handler(error) 36 dp.add_error_handler(error)
29 updater.start_polling() 37 updater.start_polling()
30 updater.idle() 38 updater.idle()
39
31if __name__ == "__main__": 40if __name__ == "__main__":
32 main() 41 main()
Powered by cgit v1.2.3 (git 2.41.0)