Commit 9a4ce398726fb3e8b6f2cd662b83c800382fa246

Authored by Noah ago
1 parent d023d74e49
Exists in master

r.piki 에서 자동으로 클릭수를 수집

Showing 3 changed files with 62 additions and 29 deletions Side-by-side Diff

insight/base62.py View file @ 9a4ce39
... ... @@ -3,7 +3,6 @@
3 3 class Base62() :
4 4 set = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
5 5  
6   -
7 6 def encode (self,i):
8 7  
9 8 if (i <= 0) :
10 9  
... ... @@ -19,12 +18,12 @@
19 18 if (str(s) <= 0) :
20 19 return 0
21 20 ret = 0
22   - len = s.__len__()
23   - for i in range(len):
  21 + length = len(s)
  22 + for i in range(length):
24 23 c = s[i]
25 24 for j in range(62) :
26 25 if c == self.set[j] :
27   - ret = ret + (j * pow(62,(len - i - 1)))
  26 + ret = ret + (j * pow(62,(length - i - 1)))
28 27 break
29 28 return ret
insight/url.py View file @ 9a4ce39
... ... @@ -2,29 +2,41 @@
2 2  
3 3 import requests
4 4 from base62 import Base62
  5 +import json
5 6  
6 7 class Url() :
7 8  
8 9 def url2dic(self, links):
9 10 data = []
10 11  
11   - try:
  12 + if (True):
12 13 for link in links:
13 14  
14   -
15 15 if len(link) < 5:
16 16 continue
17 17  
18   - if (self.isdeep(link) or self.isrpiki(link)) :
  18 + if self.isdeep(link) :
19 19  
20 20 data.append({
21 21 'bitly_url' : "",
22 22 'origin_url': str(link),
23 23 'bitly_click': "0",
24   - 'piki_cid' : str(self.getUrl2Cid(link))
  24 + 'piki_cid' : str(self.Url2Cid(link)),
  25 + 'rpiki_click' : "0"
25 26 })
26 27  
  28 + elif self.isrpiki(link) :
  29 +
  30 + data.append({
  31 + 'bitly_url' : "",
  32 + 'origin_url': str(link),
  33 + 'bitly_click': "0",
  34 + 'piki_cid' : str(self.Url2Cid(link)),
  35 + 'rpiki_click' : str(self.rpiki2click(link))
  36 + })
  37 +
27 38 elif self.isbitly(link):
  39 +
28 40 link_meta = link + "+"
29 41 txt = requests.get(link_meta).text
30 42  
31 43  
32 44  
33 45  
34 46  
... ... @@ -44,30 +56,32 @@
44 56 except:
45 57 piki_url = str(0)
46 58  
47   - data.append({
48   - 'bitly_url' : str(link),
49   - 'origin_url': str(txt[source_bgn:source_end]),
50   - 'bitly_click': str(txt[clicks_bgn:clicks_end]),
51   - 'piki_cid' : str(Base62().decode(piki_url))
52   - })
  59 + if self.isrpiki(txt[source_bgn:source_end]) :
  60 + data.append({
  61 + 'bitly_url' : str(link),
  62 + 'origin_url': str(txt[source_bgn:source_end]),
  63 + 'bitly_click': str(txt[clicks_bgn:clicks_end]),
  64 + 'piki_cid' : str(Base62().decode(piki_url)),
  65 + 'rpiki_click' : str(self.rpiki2click(txt[source_bgn:source_end]))
  66 + })
53 67  
54   - except:
55   - data.append({
56   - 'bitly_url' : "",
57   - 'origin_url': "",
58   - 'bitly_click': "0",
59   - 'piki_cid' : "0"
60   - })
  68 + else:
  69 + data.append({
  70 + 'bitly_url' : str(link),
  71 + 'origin_url': str(txt[source_bgn:source_end]),
  72 + 'bitly_click': str(txt[clicks_bgn:clicks_end]),
  73 + 'piki_cid' : str(Base62().decode(piki_url)),
  74 + 'rpiki_click' : "0"
  75 + })
61 76  
62 77 if len(data) == 0:
63   - data.append({'bitly_url' : "",'origin_url': "",'bitly_click': "0",'piki_cid' : "0"})
  78 + data.append({'bitly_url' : "",'origin_url': "",'bitly_click': "0",'piki_cid' : "0",'rpiki_click' : "0"})
64 79  
65   - #print data
66 80 return data
67 81  
68 82  
69 83  
70   - def getUrl2Cid(self,url):
  84 + def Url2Cid(self,url):
71 85  
72 86 if self.isrpiki(url):
73 87 return Base62().decode(url.split("cid=")[1].split("&")[0])
74 88  
... ... @@ -77,7 +91,26 @@
77 91 except :
78 92 return "0"
79 93  
  94 + def rpiki2click(self,url):
  95 + #print url
  96 + api = "http://contents-data.pikicast.com/contents_RPIKI_api/"
80 97  
  98 + try:
  99 + cid = url.split("cid=")[1].split("&")[0]
  100 + fr = url.split("fr=")[1].split("&")[0]
  101 + m = url.split("m=")[1].split("&")[0]
  102 + c = url.split("c=")[1].split("&")[0]
  103 + v = url.split("v=")[1].split("&")[0]
  104 + t = url.split("t=")[1].split("&")[0]
  105 + data = json.loads(requests.get(api + cid + '_' + fr + '_' + m + '_' + c + '_' + v + '_' + t).text)
  106 + ret = data['data']['real']
  107 + if ret == "":
  108 + ret = "0"
  109 + except:
  110 + ret = "0"
  111 +
  112 + return ret
  113 +
81 114 def getText2bitly(self,text):
82 115 return "http://bit.ly/" + text.split("http://bit.ly/")[1].split(" ")[0]
83 116  
... ... @@ -90,7 +123,6 @@
90 123 return False
91 124  
92 125 def isrpiki(self, url):
93   -
94 126 if url.find("//r.pikicast.com/") > 0 :
95 127 return True
96 128 else:
... ... @@ -27,12 +27,12 @@
27 27 created_time = content['created_time'].replace('T'," ").replace('+0000',"")
28 28  
29 29 try:
30   - message = content['message'].replace('\n',"").replace('\r',"").replace('',"")
  30 + message = content['message'].replace('\n'," ").replace('\r'," ").replace('',"")
31 31 except:
32 32 message = ""
33 33  
34 34 try:
35   - message_url = Url().getText2bitly(content['message'])
  35 + message_url = Url().getText2bitly(message)
36 36 except:
37 37 message_url = ""
38 38  
39 39  
... ... @@ -97,8 +97,8 @@
97 97 sqlprefix += "`bit_click`, "
98 98 sqlprefix += "`origin_url`, "
99 99 sqlprefix += "`piki_cid`, "
  100 + sqlprefix += "`rpiki_click`, "
100 101  
101   -
102 102 sqlvalues += p_id + ", "
103 103 sqlvalues += c_id + ", "
104 104 sqlvalues += "'" + insight.getContentType() + "', "
... ... @@ -114,6 +114,7 @@
114 114 sqlvalues += url_data['bitly_click'] + ", "
115 115 sqlvalues += "'" + url_data['origin_url'] + "', "
116 116 sqlvalues += url_data['piki_cid'] + ", "
  117 + sqlvalues += url_data['rpiki_click'] + ", "
117 118  
118 119 for list in lists:
119 120 sqlprefix += "`" + list.replace(',','_') + "`, "