Blame view
insight/url.py
4.95 KB
cd3f2b98c
|
1 2 3 4 |
# -*- coding: utf-8 -*- import requests from base62 import Base62 |
9a4ce3987
|
5 |
import json |
24d172161
|
6 |
import re |
cd3f2b98c
|
7 8 |
class Url() : |
9a37ba221
|
9 |
server = "http://10.128.0.20/" |
cd3f2b98c
|
10 11 |
def url2dic(self, links): data = [] |
9a4ce3987
|
12 |
if (True): |
cd3f2b98c
|
13 |
for link in links: |
b11b0e38b
|
14 15 |
link = link.replace(' '," ").replace('\r'," ").replace('\'',"") |
cd3f2b98c
|
16 17 |
if len(link) < 5: continue |
9a4ce3987
|
18 19 20 21 22 23 24 25 26 27 28 |
if self.isdeep(link) : data.append({ 'bitly_url' : "", 'origin_url': str(link), 'bitly_click': "0", 'piki_cid' : str(self.Url2Cid(link)), 'rpiki_click' : "0" }) elif self.isrpiki(link) : |
9a37ba221
|
29 30 |
print "여기?" print link |
cd3f2b98c
|
31 32 33 34 |
data.append({ 'bitly_url' : "", 'origin_url': str(link), 'bitly_click': "0", |
9a4ce3987
|
35 36 |
'piki_cid' : str(self.Url2Cid(link)), 'rpiki_click' : str(self.rpiki2click(link)) |
cd3f2b98c
|
37 38 39 |
}) elif self.isbitly(link): |
9a4ce3987
|
40 |
|
24d172161
|
41 |
try: |
b11b0e38b
|
42 |
link = "http://bit.ly/" + re.compile('[^./a-zA-Z0-9]+').sub("",link.split("//bit.ly/")[1].split(" ")[0]) |
24d172161
|
43 44 45 |
link_meta = link + "+" txt = requests.get(link_meta).text |
cd3f2b98c
|
46 |
|
24d172161
|
47 48 |
source_tag_op = "\"long_url\": \"" source_tag_cl = "\"" |
cd3f2b98c
|
49 |
|
24d172161
|
50 51 |
clicks_tag_op = "\"user_clicks\": " clicks_tag_cl = "," |
cd3f2b98c
|
52 |
|
24d172161
|
53 54 55 56 57 58 59 |
source_bgn = txt.find(source_tag_op) + len(source_tag_op) source_end = source_bgn + txt[source_bgn:(source_bgn + 500)].find(source_tag_cl) clicks_bgn = txt.find(clicks_tag_op) + len(clicks_tag_op) clicks_end = clicks_bgn + txt[clicks_bgn:(clicks_bgn + 50)].find(clicks_tag_cl) except: data.append({'bitly_url' : "",'origin_url': "",'bitly_click': "0",'piki_cid' : "0",'rpiki_click' : "0"}) |
cd3f2b98c
|
60 61 62 63 64 |
try: piki_url = str(txt[source_bgn:source_end]).split("cid=")[1].split("&")[0] except: piki_url = str(0) |
9a4ce3987
|
65 66 67 68 69 70 71 72 73 74 |
if self.isrpiki(txt[source_bgn:source_end]) : data.append({ 'bitly_url' : str(link), 'origin_url': str(txt[source_bgn:source_end]), 'bitly_click': str(txt[clicks_bgn:clicks_end]), 'piki_cid' : str(Base62().decode(piki_url)), 'rpiki_click' : str(self.rpiki2click(txt[source_bgn:source_end])) }) else: |
077e29190
|
75 |
#print link |
9a4ce3987
|
76 77 78 79 80 81 82 |
data.append({ 'bitly_url' : str(link), 'origin_url': str(txt[source_bgn:source_end]), 'bitly_click': str(txt[clicks_bgn:clicks_end]), 'piki_cid' : str(Base62().decode(piki_url)), 'rpiki_click' : "0" }) |
cd3f2b98c
|
83 84 |
if len(data) == 0: |
9a4ce3987
|
85 |
data.append({'bitly_url' : "",'origin_url': "",'bitly_click': "0",'piki_cid' : "0",'rpiki_click' : "0"}) |
cd3f2b98c
|
86 |
|
cd3f2b98c
|
87 |
return data |
9a4ce3987
|
88 |
def Url2Cid(self,url): |
cd3f2b98c
|
89 |
|
47237816c
|
90 91 92 93 |
try: if self.isrpiki(url): return Base62().decode(url.split("cid=")[1].split("&")[0]) elif self.isdeep(url): |
cd3f2b98c
|
94 |
return requests.get(url).text.split("http://www.pikicast.com/share/")[1].split('"')[0] |
47237816c
|
95 96 |
except : return "0" |
cd3f2b98c
|
97 |
|
9a4ce3987
|
98 99 |
def rpiki2click(self,url): #print url |
9a37ba221
|
100 |
api = self.server + "contents_RPIKI_api/" |
9a4ce3987
|
101 102 |
try: |
9a4ce3987
|
103 |
fr = url.split("fr=")[1].split("&")[0] |
9a37ba221
|
104 105 106 107 108 |
except: fr = "" try: cid = url.split("cid=")[1].split("&")[0] |
9a4ce3987
|
109 110 111 112 113 114 115 116 117 118 119 120 |
m = url.split("m=")[1].split("&")[0] c = url.split("c=")[1].split("&")[0] v = url.split("v=")[1].split("&")[0] t = url.split("t=")[1].split("&")[0] data = json.loads(requests.get(api + cid + '_' + fr + '_' + m + '_' + c + '_' + v + '_' + t).text) ret = data['data']['real'] if ret == "": ret = "0" except: ret = "0" return ret |
cd3f2b98c
|
121 122 |
def getText2bitly(self,text): |
d023d74e4
|
123 |
return "http://bit.ly/" + text.split("http://bit.ly/")[1].split(" ")[0] |
cd3f2b98c
|
124 125 126 127 128 129 130 131 132 133 |
def isdeep(self, url): if url.find("//fb.me/") > 0 : return True else: return False def isrpiki(self, url): |
cd3f2b98c
|
134 135 136 137 138 139 140 141 142 143 144 |
if url.find("//r.pikicast.com/") > 0 : return True else: return False def isbitly(self, url): if url.find("//bit.ly/") > 0 : return True else: return False |
9a4ce3987
|
145 |