Commit 1da42fd6135d755c11bfc4d4f40db41da86b9add

Authored by steve ago
Exists in master

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

Showing 2 changed files Side-by-side Diff

insight/postinsight.py View file @ 1da42fd
... ... @@ -23,16 +23,20 @@
23 23  
24 24 def setContentInsight(self,content_id):
25 25  
26   - url ='https://graph.facebook.com/v2.5/%s?fields=message,created_time,link,comments.limit(5),type,insights{values}'%content_id
27   - txt = requests.get(url + self.token).text
28   - #print url + self.token
29   - self.data = json.loads(txt)
30   - self.setContentType(self.data)
31   - self.setContentComment(self.data)
32   - self.setLinkUrl(self.data)
33   - self.setContentCreated_time(self.data)
34   - #print self.data
35 26 try:
  27 + url ='https://graph.facebook.com/v2.5/%s?fields=message,created_time,link,comments.limit(5),type,insights{values}'%content_id
  28 + txt = requests.get(url + self.token).text
  29 + #print url + self.token
  30 + self.data = json.loads(txt)
  31 + self.setContentType(self.data)
  32 + self.setContentComment(self.data)
  33 + self.setLinkUrl(self.data)
  34 + self.setContentMessage(self.data)
  35 + self.setContentCreated_time(self.data)
  36 + #print self.data
  37 + except:
  38 + return
  39 + try:
36 40 for i in self.data['insights']['data']:
37 41 name = i['id'].split("/")[2]
38 42 values = i['values'][0]
... ... @@ -70,7 +74,7 @@
70 74  
71 75 def setContentMessage(self, data):
72 76 try:
73   - self.message = data['created_time']
  77 + self.message = data['message']
74 78 except:
75 79 self.message = ""
76 80  
... ... @@ -15,7 +15,7 @@
15 15 token = Token()
16 16  
17 17 contexts = Context(token)
18   - contexts.setContextsFeedAndTimestemp(3600 * 24 * 10)
  18 + contexts.setContextsFeedAndTimestemp(3600 * 24 * 31 * 12)
19 19 contents_list = contexts.getContentsList()
20 20  
21 21 for content in contents_list:
... ... @@ -116,7 +116,7 @@
116 116 sqlprefix = sqlprefix[:len(sqlprefix)-2] + ")"
117 117 sqlvalues = sqlvalues[:len(sqlvalues)-2] + ");"
118 118  
119   - print sqlprefix + sqlvalues
  119 + #print sqlprefix + sqlvalues
120 120  
121 121 datadb.fb_insert(sqlprefix + sqlvalues)
122 122 datadb.fb_insert(sqlreplace + sqlprefix[32:] + sqlvalues)