Commit c3f034c7568b9d3b6400836a8d9c5153c0d354a8
1 parent
47237816c6
Exists in
master
단일 컨텐츠를 수동 반영 가능
Showing 3 changed files with 189 additions and 9 deletions Side-by-side Diff
insight/postinsight.py
View file @
c3f034c
... | ... | @@ -12,6 +12,8 @@ |
12 | 12 | type = "" |
13 | 13 | link = "" |
14 | 14 | comment = "" |
15 | + created_time = "" | |
16 | + message = "" | |
15 | 17 | data = {} |
16 | 18 | insight_map = {} |
17 | 19 | |
... | ... | @@ -21,7 +23,7 @@ |
21 | 23 | |
22 | 24 | def setContentInsight(self,content_id): |
23 | 25 | |
24 | - url ='https://graph.facebook.com/v2.5/%s?fields=link,comments.limit(5),type,insights{values}'%content_id | |
26 | + url ='https://graph.facebook.com/v2.5/%s?fields=message,created_time,link,comments.limit(5),type,insights{values}'%content_id | |
25 | 27 | txt = requests.get(url + self.token).text |
26 | 28 | #print url + self.token |
27 | 29 | self.data = json.loads(txt) |
... | ... | @@ -58,6 +60,19 @@ |
58 | 60 | def getContentInsightAll(self): |
59 | 61 | return self.insight_map |
60 | 62 | |
63 | + | |
64 | + def setContentCreated_time(self, data): | |
65 | + try: | |
66 | + self.created_time = data['created_time'] | |
67 | + except: | |
68 | + self.created_time = "" | |
69 | + | |
70 | + def setContentMessage(self, data): | |
71 | + try: | |
72 | + self.message = data['created_time'] | |
73 | + except: | |
74 | + self.message = "" | |
75 | + | |
61 | 76 | def setContentType(self, data): |
62 | 77 | try: |
63 | 78 | self.type = data['type'] |
... | ... | @@ -86,4 +101,16 @@ |
86 | 101 | |
87 | 102 | def getContentCommentUrl(self): |
88 | 103 | return self.comment |
104 | + | |
105 | + def getContentCreated_time(self): | |
106 | + try: | |
107 | + return self.created_time.replace('T'," ").replace('+0000',"") | |
108 | + except: | |
109 | + return "" | |
110 | + | |
111 | + def getContentMessage(self): | |
112 | + try: | |
113 | + return self.message.replace('\n'," ").replace('\r'," ").replace('\'',"") | |
114 | + except: | |
115 | + return "" |
insight/url.py
View file @
c3f034c
... | ... | @@ -17,6 +17,8 @@ |
17 | 17 | |
18 | 18 | link = link.replace('\n'," ").replace('\r'," ").replace('\'',"") |
19 | 19 | |
20 | + print link | |
21 | + | |
20 | 22 | if len(link) < 5: |
21 | 23 | continue |
22 | 24 | |
... | ... | @@ -31,7 +33,6 @@ |
31 | 33 | }) |
32 | 34 | |
33 | 35 | elif self.isrpiki(link) : |
34 | - print "여기?" | |
35 | 36 | print link |
36 | 37 | data.append({ |
37 | 38 | 'bitly_url' : "", |
... | ... | @@ -42,7 +43,6 @@ |
42 | 43 | }) |
43 | 44 | |
44 | 45 | elif self.isbitly(link): |
45 | - | |
46 | 46 | try: |
47 | 47 | link = "http://bit.ly/" + re.compile('[^./a-zA-Z0-9]+').sub("",link.split("//bit.ly/")[1].split(" ")[0]) |
48 | 48 | |
... | ... | @@ -68,6 +68,8 @@ |
68 | 68 | except: |
69 | 69 | piki_url = str(0) |
70 | 70 | |
71 | + print self.rpiki2click(txt[source_bgn:source_end]) | |
72 | + | |
71 | 73 | if self.isrpiki(txt[source_bgn:source_end]) : |
72 | 74 | data.append({ |
73 | 75 | 'bitly_url' : str(link), |
74 | 76 | |
75 | 77 | |
76 | 78 | |
77 | 79 | |
78 | 80 | |
79 | 81 | |
80 | 82 | |
81 | 83 | |
82 | 84 | |
... | ... | @@ -105,32 +107,51 @@ |
105 | 107 | return "0" |
106 | 108 | |
107 | 109 | def rpiki2click(self,url): |
108 | - #print url | |
110 | + print url | |
109 | 111 | api = self.server + "contents_RPIKI_api/" |
110 | 112 | |
111 | 113 | try: |
112 | 114 | fr = url.split("fr=")[1].split("&")[0] |
113 | 115 | except: |
114 | 116 | fr = "" |
115 | - | |
116 | 117 | try: |
117 | 118 | cid = url.split("cid=")[1].split("&")[0] |
119 | + except: | |
120 | + cid = "" | |
121 | + try: | |
118 | 122 | m = url.split("m=")[1].split("&")[0] |
123 | + except: | |
124 | + m = "" | |
125 | + try: | |
119 | 126 | c = url.split("c=")[1].split("&")[0] |
127 | + except: | |
128 | + c ="" | |
129 | + try: | |
120 | 130 | v = url.split("v=")[1].split("&")[0] |
131 | + except: | |
132 | + v = "" | |
133 | + try: | |
121 | 134 | t = url.split("t=")[1].split("&")[0] |
135 | + except: | |
136 | + t = "" | |
137 | + | |
138 | + try: | |
122 | 139 | data = json.loads(requests.get(api + cid + '_' + fr + '_' + m + '_' + c + '_' + v + '_' + t).text) |
140 | + | |
123 | 141 | ret = data['data']['real'] |
124 | 142 | if ret == "": |
125 | 143 | ret = "0" |
126 | - except: | |
144 | + except Exception as e: | |
145 | + print e | |
127 | 146 | ret = "0" |
128 | 147 | |
129 | 148 | return ret |
130 | 149 | |
131 | 150 | def getText2bitly(self,text): |
132 | - return "http://bit.ly/" + text.split("http://bit.ly/")[1].split(" ")[0] | |
133 | - | |
151 | + try: | |
152 | + return "http://bit.ly/" + text.split("http://bit.ly/")[1].split(" ")[0] | |
153 | + except: | |
154 | + return "" | |
134 | 155 | |
135 | 156 | def isdeep(self, url): |
136 | 157 |
runcontent.py
View file @
c3f034c
1 | +#!/usr/bin/env python | |
2 | +# -*- coding: utf-8 -*- | |
3 | + | |
4 | +from insight.context import Context | |
5 | +from insight.token import Token | |
6 | +from insight.postinsight import PostInsight | |
7 | +from insight.datadb import DataDB | |
8 | + | |
9 | +from insight.url import Url | |
10 | +import time | |
11 | + | |
12 | + | |
13 | +if __name__=='__main__': | |
14 | + | |
15 | + token = Token() | |
16 | + contents_list = [] | |
17 | + | |
18 | + | |
19 | + contents_list.append({"id": "467342726674321_1159260310815889"}) | |
20 | + | |
21 | + | |
22 | + | |
23 | + for content in contents_list: | |
24 | + datadb = DataDB() | |
25 | + time.sleep(1) | |
26 | + p_id = str(content['id'].split('_')[0]) | |
27 | + c_id = str(content['id'].split('_')[1]) | |
28 | + | |
29 | + insight = PostInsight(token) | |
30 | + insight.setContentInsight(content['id']) | |
31 | + | |
32 | + created_time = insight.getContentCreated_time() | |
33 | + message = insight.getContentMessage() | |
34 | + message_url = Url().getText2bitly(message) | |
35 | + | |
36 | + lists =["post_story_adds_unique", | |
37 | + "post_story_adds", | |
38 | + "post_story_adds_by_action_type_unique,comment", | |
39 | + "post_story_adds_by_action_type_unique,like", | |
40 | + "post_story_adds_by_action_type_unique,share", | |
41 | + "post_story_adds_by_action_type,comment", | |
42 | + "post_impressions", | |
43 | + "post_impressions_paid_unique", | |
44 | + "post_impressions_paid", | |
45 | + "post_story_adds_by_action_type,like", | |
46 | + "post_story_adds_by_action_type,share", | |
47 | + "post_impressions_unique", | |
48 | + "post_impressions_organic_unique", | |
49 | + "post_impressions_organic", | |
50 | + "post_impressions_by_story_type_unique,other", | |
51 | + "post_impressions_by_story_type,other", | |
52 | + "post_consumptions_by_type_unique,other clicks", | |
53 | + "post_consumptions_by_type_unique,photo view", | |
54 | + "post_consumptions_by_type_unique,video play", | |
55 | + "post_consumptions_by_type_unique,link clicks", | |
56 | + "post_consumptions_by_type,other clicks", | |
57 | + "post_consumptions_by_type,photo view", | |
58 | + "post_consumptions_by_type,video play", | |
59 | + "post_consumptions_by_type,link clicks", | |
60 | + "post_engaged_users", | |
61 | + "post_video_views", | |
62 | + "post_video_views_unique", | |
63 | + "post_video_views_paid", | |
64 | + "post_video_views_autoplayed", | |
65 | + "post_video_views_10s", | |
66 | + "post_video_views_10s_unique", | |
67 | + "post_video_views_10s_paid", | |
68 | + "post_video_views_10s_organic", | |
69 | + "post_video_views_10s_clicked_to_play", | |
70 | + "post_video_views_10s_autoplayed", | |
71 | + "post_video_views_10s_sound_on", | |
72 | + "post_video_views_sound_on", | |
73 | + "post_video_view_time", | |
74 | + "post_video_complete_views_organic", | |
75 | + "post_video_complete_views_paid"] | |
76 | + | |
77 | + sqlprefix = "insert into facebook_insights2 (" | |
78 | + sqlreplace = "REPLACE into facebook_insights2_last (" | |
79 | + sqlvalues = " values (" | |
80 | + | |
81 | + sqlprefix += "`p_id`, " | |
82 | + sqlprefix += "`c_id`, " | |
83 | + sqlprefix += "`type`, " | |
84 | + sqlprefix += "`message`, " | |
85 | + sqlprefix += "`message_url`, " | |
86 | + sqlprefix += "`comment_url`, " | |
87 | + sqlprefix += "`created_time`, " | |
88 | + sqlprefix += "`loging_time`, " | |
89 | + | |
90 | + sqlprefix += "`bit_url`, " | |
91 | + sqlprefix += "`bit_click`, " | |
92 | + sqlprefix += "`origin_url`, " | |
93 | + sqlprefix += "`piki_cid`, " | |
94 | + sqlprefix += "`rpiki_click`, " | |
95 | + | |
96 | + sqlvalues += p_id + ", " | |
97 | + sqlvalues += c_id + ", " | |
98 | + sqlvalues += "'" + insight.getContentType() + "', " | |
99 | + sqlvalues += "'" + message + "', " | |
100 | + sqlvalues += "'" + message_url + "', " | |
101 | + sqlvalues += "'" + insight.getContentCommentUrl() + "', " | |
102 | + sqlvalues += "'" + created_time + "', " | |
103 | + sqlvalues += "NOW(), " | |
104 | + | |
105 | + | |
106 | + | |
107 | + url_data = Url().url2dic([insight.getLinkUrl(),message_url,insight.getContentCommentUrl()])[0] | |
108 | + | |
109 | + sqlvalues += "'" + url_data['bitly_url'] + "', " | |
110 | + sqlvalues += url_data['bitly_click'] + ", " | |
111 | + sqlvalues += "'" + url_data['origin_url'] + "', " | |
112 | + sqlvalues += url_data['piki_cid'] + ", " | |
113 | + sqlvalues += url_data['rpiki_click'] + ", " | |
114 | + | |
115 | + for list in lists: | |
116 | + sqlprefix += "`" + list.replace(',','_') + "`, " | |
117 | + sqlvalues += str(insight.getContentInsightByKey(list)) + ", " | |
118 | + | |
119 | + sqlprefix = sqlprefix[:len(sqlprefix)-2] + ")" | |
120 | + sqlvalues = sqlvalues[:len(sqlvalues)-2] + ");" | |
121 | + | |
122 | + print sqlprefix + sqlvalues | |
123 | + | |
124 | + datadb.fb_insert(sqlprefix + sqlvalues) | |
125 | + datadb.fb_insert(sqlreplace + sqlprefix[32:] + sqlvalues) | |
126 | + | |
127 | + | |
128 | + del(datadb) | |
129 | + del(insight) |