Commit d484479040015da9bfde6c3eb63c2ac6ed02ee37

Authored by steve ago
Exists in master

Merge branch 'master' of http://gitlab.pikicast.com/Noah/dsfacebook

Showing 1 changed file Inline Diff

#!/usr/bin/env python 1 1 #!/usr/bin/env python
# -*- coding: utf-8 -*- 2 2 # -*- coding: utf-8 -*-
3 3
from insight.context import Context 4 4 from insight.context import Context
from insight.token import Token 5 5 from insight.token import Token
from insight.postinsight import PostInsight 6 6 from insight.postinsight import PostInsight
from insight.datadb import DataDB 7 7 from insight.datadb import DataDB
8 8
from insight.url import Url 9 9 from insight.url import Url
import time 10 10 import time
11 11
12 12
if __name__=='__main__': 13 13 if __name__=='__main__':
14 14
#token_str = "EAAUTLd5JgaoBAJMeeMXqcdExQ1egUHeBaIgVBCilmiH4K9RNyUt7gSgVZCZAtszWCLEaZCDQpxewhICtFjNRICFPWAqUygshcSsdEZBUeZAyUJkON7bfQ2NFFI5AqifNahzjFT83GkWZCZCZBXO3050XSjFf9HSR0iAZD" 15 15 #token_str = "EAAUTLd5JgaoBAJMeeMXqcdExQ1egUHeBaIgVBCilmiH4K9RNyUt7gSgVZCZAtszWCLEaZCDQpxewhICtFjNRICFPWAqUygshcSsdEZBUeZAyUJkON7bfQ2NFFI5AqifNahzjFT83GkWZCZCZBXO3050XSjFf9HSR0iAZD"
token = Token() 16 16 token = Token()
17 17
contexts = Context(token) 18 18 contexts = Context(token)
contexts.setContextsFeedAndTimestemp(3600 * 24 * 10 * 3) 19 19 contexts.setContextsFeedAndTimestemp(3600 * 24 * 10 )
contents_list = contexts.getContentsList() 20 20 contents_list = contexts.getContentsList()
21 21
for content in contents_list: 22 22 for content in contents_list:
datadb = DataDB() 23 23 datadb = DataDB()
time.sleep(1) 24 24 time.sleep(1)
p_id = str(content['id'].split('_')[0]) 25 25 p_id = str(content['id'].split('_')[0])
c_id = str(content['id'].split('_')[1]) 26 26 c_id = str(content['id'].split('_')[1])
created_time = content['created_time'].replace('T'," ").replace('+0000',"") 27 27 created_time = content['created_time'].replace('T'," ").replace('+0000',"")
28 28
try: 29 29 try:
message = content['message'].replace('\n'," ").replace('\r'," ").replace('\'',"") 30 30 message = content['message'].replace('\n'," ").replace('\r'," ").replace('\'',"")
except: 31 31 except:
message = "" 32 32 message = ""
33 33
try: 34 34 try:
message_url = Url().getText2bitly(message) 35 35 message_url = Url().getText2bitly(message)
except: 36 36 except:
message_url = "" 37 37 message_url = ""
38 38
insight = PostInsight(token) 39 39 insight = PostInsight(token)
insight.setContentInsight(content['id']) 40 40 insight.setContentInsight(content['id'])
41 41
lists =["post_story_adds_unique", 42 42 lists =["post_story_adds_unique",
"post_story_adds", 43 43 "post_story_adds",
"post_story_adds_by_action_type_unique,comment", 44 44 "post_story_adds_by_action_type_unique,comment",
"post_story_adds_by_action_type_unique,like", 45 45 "post_story_adds_by_action_type_unique,like",
"post_story_adds_by_action_type_unique,share", 46 46 "post_story_adds_by_action_type_unique,share",
"post_story_adds_by_action_type,comment", 47 47 "post_story_adds_by_action_type,comment",
"post_impressions", 48 48 "post_impressions",
"post_impressions_paid_unique", 49 49 "post_impressions_paid_unique",
"post_impressions_paid", 50 50 "post_impressions_paid",
"post_story_adds_by_action_type,like", 51 51 "post_story_adds_by_action_type,like",
"post_story_adds_by_action_type,share", 52 52 "post_story_adds_by_action_type,share",
"post_impressions_unique", 53 53 "post_impressions_unique",
"post_impressions_organic_unique", 54 54 "post_impressions_organic_unique",
"post_impressions_organic", 55 55 "post_impressions_organic",
"post_impressions_by_story_type_unique,other", 56 56 "post_impressions_by_story_type_unique,other",
"post_impressions_by_story_type,other", 57 57 "post_impressions_by_story_type,other",
"post_consumptions_by_type_unique,other clicks", 58 58 "post_consumptions_by_type_unique,other clicks",
"post_consumptions_by_type_unique,photo view", 59 59 "post_consumptions_by_type_unique,photo view",
"post_consumptions_by_type_unique,video play", 60 60 "post_consumptions_by_type_unique,video play",
"post_consumptions_by_type_unique,link clicks", 61 61 "post_consumptions_by_type_unique,link clicks",
"post_consumptions_by_type,other clicks", 62 62 "post_consumptions_by_type,other clicks",
"post_consumptions_by_type,photo view", 63 63 "post_consumptions_by_type,photo view",
"post_consumptions_by_type,video play", 64 64 "post_consumptions_by_type,video play",
"post_consumptions_by_type,link clicks", 65 65 "post_consumptions_by_type,link clicks",
"post_engaged_users", 66 66 "post_engaged_users",
"post_video_views", 67 67 "post_video_views",
"post_video_views_unique", 68 68 "post_video_views_unique",
"post_video_views_paid", 69 69 "post_video_views_paid",
"post_video_views_autoplayed", 70 70 "post_video_views_autoplayed",
"post_video_views_10s", 71 71 "post_video_views_10s",
"post_video_views_10s_unique", 72 72 "post_video_views_10s_unique",
"post_video_views_10s_paid", 73 73 "post_video_views_10s_paid",
"post_video_views_10s_organic", 74 74 "post_video_views_10s_organic",
"post_video_views_10s_clicked_to_play", 75 75 "post_video_views_10s_clicked_to_play",
"post_video_views_10s_autoplayed", 76 76 "post_video_views_10s_autoplayed",
"post_video_views_10s_sound_on", 77 77 "post_video_views_10s_sound_on",
"post_video_views_sound_on", 78 78 "post_video_views_sound_on",
"post_video_view_time", 79 79 "post_video_view_time",
"post_video_complete_views_organic", 80 80 "post_video_complete_views_organic",
"post_video_complete_views_paid"] 81 81 "post_video_complete_views_paid"]
82 82
sqlprefix = "insert into facebook_insights2 (" 83 83 sqlprefix = "insert into facebook_insights2 ("
sqlreplace = "REPLACE into facebook_insights2_last (" 84 84 sqlreplace = "REPLACE into facebook_insights2_last ("
sqlvalues = " values (" 85 85 sqlvalues = " values ("
86 86
sqlprefix += "`p_id`, " 87 87 sqlprefix += "`p_id`, "
sqlprefix += "`c_id`, " 88 88 sqlprefix += "`c_id`, "
sqlprefix += "`type`, " 89 89 sqlprefix += "`type`, "
sqlprefix += "`message`, " 90 90 sqlprefix += "`message`, "
sqlprefix += "`message_url`, " 91 91 sqlprefix += "`message_url`, "
sqlprefix += "`comment_url`, " 92 92 sqlprefix += "`comment_url`, "
sqlprefix += "`created_time`, " 93 93 sqlprefix += "`created_time`, "
sqlprefix += "`loging_time`, " 94 94 sqlprefix += "`loging_time`, "
95 95
sqlprefix += "`bit_url`, " 96 96 sqlprefix += "`bit_url`, "
sqlprefix += "`bit_click`, " 97 97 sqlprefix += "`bit_click`, "
sqlprefix += "`origin_url`, " 98 98 sqlprefix += "`origin_url`, "
sqlprefix += "`piki_cid`, " 99 99 sqlprefix += "`piki_cid`, "
sqlprefix += "`rpiki_click`, " 100 100 sqlprefix += "`rpiki_click`, "
101 101
sqlvalues += p_id + ", " 102 102 sqlvalues += p_id + ", "
sqlvalues += c_id + ", " 103 103 sqlvalues += c_id + ", "
sqlvalues += "'" + insight.getContentType() + "', " 104 104 sqlvalues += "'" + insight.getContentType() + "', "
sqlvalues += "'" + message + "', " 105 105 sqlvalues += "'" + message + "', "
sqlvalues += "'" + message_url + "', " 106 106 sqlvalues += "'" + message_url + "', "
sqlvalues += "'" + insight.getContentCommentUrl() + "', " 107 107 sqlvalues += "'" + insight.getContentCommentUrl() + "', "
sqlvalues += "'" + created_time + "', " 108 108 sqlvalues += "'" + created_time + "', "
sqlvalues += "NOW(), " 109 109 sqlvalues += "NOW(), "
110 110
url_data = Url().url2dic([insight.getLinkUrl(),message_url,insight.getContentCommentUrl()])[0] 111 111 url_data = Url().url2dic([insight.getLinkUrl(),message_url,insight.getContentCommentUrl()])[0]