chenjunkai il y a 6 ans
Parent
commit
7d738abd87
2 fichiers modifiés avec 32 ajouts et 19 suppressions
  1. 21 17
      Ansjer/test/test.py
  2. 11 2
      Controller/DetectController.py

+ 21 - 17
Ansjer/test/test.py

@@ -1,20 +1,24 @@
-import ipdb
+#!/usr/bin/env python3.3
+from pyawk import PyAwk, p
+class LTSVParser(PyAwk):
+    def begin(self):
+        self.FS = '\t'
+        self.count = 0
 
-db = ipdb.City("D:/13.56.215.252/git/AnsjerFormal/DB/mydata4vipday2.ipdb")
-db.reload("/path/to/city.ipv4.ipdb") # update ipdb database file reload data
-# print(db.is_ipv4(), db.is_ipv6())
-# print(db.languages())  # support language
-# print(db.fields())  # support fields
-# print(db.build_time())  # build database time
-# print(db.languages())
-# xx = db.find_info("13.56.215.252", "EN")
-xx = db.find_map("13.56.215.252", "EN")
+    def action(self, S):
+        if not p(S[0], r'status:200'):
+            self.count += 1
+            self.print('----------')
+            d = {}
+            for elem in S[1:]:
+                key, value = elem.split(':', 1)
+                d[key] = value
+            self.print(d)
 
-from var_dump import var_dump
+    def end(self):
+        self.print('----------')
+        self.print('Total:{}'.format(self.NR))
+        self.print('Matched:{}'.format(self.count))
 
-var_dump(xx)
-exit()
-print()  # query ip return array
-# print(db.find(u"1.1.1.1", "CN")) #  Python 2.7
-print(db.find_map("8.8.8.8", "CN"))  # query ip return dict
-print(db.find_info("118.28.1.1", "CN").country_name) 
+if __name__ == '__main__':
+    LTSVParser().run()

+ 11 - 2
Controller/DetectController.py

@@ -32,6 +32,7 @@ from Object.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
 from Object.UidTokenObject import UidTokenObject
 from django.http import JsonResponse
+from Object.RedisObject import RedisObject
 
 
 # http://192.168.136.40:8077/detect/changeStatus?uid=JW3684H8BSHG9TTM111A&token_val=18071adc03536302f34&appBundleId=com.ansjer.zccloud_ab&push_type=2&token=local&status=1&app_type=1
@@ -101,9 +102,9 @@ class DetectControllerView(View):
             channel = p['Channel']
             if p['is_st'] == 1:
                 p['img'] = img_bucket.sign_url('GET', '{uid}/{channel}/{time}.jpeg'.
-                                                format(uid=devUid, channel=p['Channel'], time=eventTime), 300)
+                                               format(uid=devUid, channel=p['Channel'], time=eventTime), 300)
                 p['img_list'] = [img_bucket.sign_url('GET', '{uid}/{channel}/{time}.jpeg'.
-                                                format(uid=devUid, channel=channel, time=eventTime), 300)]
+                                                     format(uid=devUid, channel=channel, time=eventTime), 300)]
             elif p['is_st'] == 2:
                 # 列表装载回放时间戳标记
                 vodqs = VodHlsModel.objects.filter(uid=devUid, channel=channel, time=int(eventTime)) \
@@ -227,11 +228,19 @@ class NotificationView(View):
             values('token_val', 'app_type', 'appBundleId', 'push_type', 'uid', 'userID_id', 'userID__NickName',
                    'interval')
         if uaqs.exists():
+            redisObj = RedisObject(db=6)
 
             auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
             bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
+
             for ua in uaqs:
                 push_type = ua['push_type']
+                pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
+                if redisObj.get_data(key=pkey):
+                    res_data = {'code': 0, 'msg': 'success,!'}
+                    return JsonResponse(status=200, data=res_data)
+                else:
+                    redisObj.set_data(key=pkey, val=1, expire=ua['interval'])
                 # ios apns
                 if push_type == 0:
                     self.do_apns(request_dict, ua, response)