Commit 2e4d69eb8063509ece6fc22c98cae82f0a0ee953

Authored by Noah ago
1 parent 8ee3b171ce
Exists in master

본문, 댓글 http://bit.ly/ url 수집

Showing 4 changed files with 46 additions and 8 deletions Side-by-side Diff

insight/context.py View file @ 2e4d69e
... ... @@ -74,11 +74,11 @@
74 74 txt = requests.get(url + self.token).text
75 75 data = json.loads(txt)
76 76 return_val.append(data)
77   - #print data
  77 + print data
78 78  
79 79 while self.isNext(data):
80 80 nextUrl = self.nextUrl(data)
81   - print nextUrl
  81 + #print nextUrl
82 82 feed_ts = int(nextUrl.split("until=")[1].split("&")[0])
83 83 if (time_now - ts) > feed_ts :
84 84 break
insight/postinsight.py View file @ 2e4d69e
... ... @@ -3,7 +3,9 @@
3 3  
4 4 import requests
5 5 import json
  6 +import util
6 7  
  8 +
7 9 class PostInsight() :
8 10  
9 11 token = ""
10 12  
11 13  
... ... @@ -17,11 +19,13 @@
17 19  
18 20 def setContentInsight(self,content_id):
19 21  
20   - url ='https://graph.facebook.com/v2.5/%s?fields=type,insights{values}'%content_id
  22 + url ='https://graph.facebook.com/v2.5/%s?fields=comments.limit(5),type,insights{values}'%content_id
21 23 txt = requests.get(url + self.token).text
  24 + #print url + self.token
22 25 self.data = json.loads(txt)
23 26 self.setContentType(self.data)
24   - #print txt
  27 + self.setContentComment(self.data)
  28 + #print self.data
25 29 try:
26 30 for i in self.data['insights']['data']:
27 31 name = i['id'].split("/")[2]
28 32  
... ... @@ -57,6 +61,17 @@
57 61 except:
58 62 self.type = ""
59 63  
  64 + def setContentComment(self, data):
  65 + try:
  66 + self.comment = util.Util().getText2Url(data['comments']['data'][0]['message'])
  67 + print self.comment
  68 + except:
  69 + self.comment = ""
  70 +
  71 +
60 72 def getContentType(self):
61 73 return self.type
  74 +
  75 + def getContentComment(self):
  76 + return self.comment
insight/util.py View file @ 2e4d69e
  1 +#!/usr/bin/env python
  2 +# -*- coding: utf-8 -*-
  3 +
  4 +
  5 +class Util() :
  6 + def getText2Url(self,text):
  7 + return "http://" + text.split("http://")[1].split(" ")[0]
  8 +
  9 +#util = Util()
  10 +#print util.getText2Url("실시간 후끈후끈한 사용 후기.jpg지금 달려!!!!!!! ▶http://bit.ly/29MEr2Z")
... ... @@ -5,13 +5,16 @@
5 5 from insight.token import Token
6 6 from insight.postinsight import PostInsight
7 7 from insight.datadb import DataDB
  8 +from insight.util import Util
8 9 import time
9 10  
10 11  
11 12 if __name__=='__main__':
12 13  
  14 + util = Util()
  15 +
13 16 #token_str = "CAAUTLd5JgaoBABnBUUgOjgaUkuviOZCC1otVIJYwYapCRTZBU8ZAbTOd1uo1SBiqHr1eBhVdzoYDoBjPzqO0ImpxGZAXtlXeVtp4r2muUDt3O53NLYqFgrJqKAowcU7fWMsmMTZAAtKT8MXeF4Lb0rHQ2I1gHmbr6nlJWBHzk6dsNPmYHguMp"
14   - token_str = "EAAUTLd5JgaoBAGni3ODjG2OWQfgbPZBf2rrs07Jjx4pCjTKVZAD6QwZCZCXZALfMkPfVltjOngqnoA1mBZBZAUwP8v6qZB3zdYecjQCOWsBfupw18GMRijaUOWeHYsCOZBk1OCxLCLnci9eZBqzuF8IGO107JZCUVK2rDkZD"
  17 + token_str = "EAAUTLd5JgaoBAJMeeMXqcdExQ1egUHeBaIgVBCilmiH4K9RNyUt7gSgVZCZAtszWCLEaZCDQpxewhICtFjNRICFPWAqUygshcSsdEZBUeZAyUJkON7bfQ2NFFI5AqifNahzjFT83GkWZCZCZBXO3050XSjFf9HSR0iAZD"
15 18 token = Token(token_str)
16 19  
17 20 contexts = Context(token)
... ... @@ -32,6 +35,12 @@
32 35 except:
33 36 message = " "
34 37  
  38 + try:
  39 + message_url = util.getText2Url(content['message'])
  40 + except:
  41 + message_url = " "
  42 +
  43 +
35 44 insight = PostInsight(token)
36 45 insight.setContentInsight(content['id'])
37 46 lists =["post_story_adds_unique",
38 47  
... ... @@ -40,12 +49,12 @@
40 49 "post_story_adds_by_action_type_unique,like",
41 50 "post_story_adds_by_action_type_unique,share",
42 51 "post_story_adds_by_action_type,comment",
43   - "post_story_adds_by_action_type,like",
44   - "post_story_adds_by_action_type,share",
45   - "post_impressions_unique",
46 52 "post_impressions",
47 53 "post_impressions_paid_unique",
48 54 "post_impressions_paid",
  55 + "post_story_adds_by_action_type,like",
  56 + "post_story_adds_by_action_type,share",
  57 + "post_impressions_unique",
49 58 "post_impressions_organic_unique",
50 59 "post_impressions_organic",
51 60 "post_impressions_by_story_type_unique,other",
... ... @@ -83,6 +92,8 @@
83 92 sqlprefix += "`c_id`, "
84 93 sqlprefix += "`type`, "
85 94 sqlprefix += "`message`, "
  95 + sqlprefix += "`message_url`, "
  96 + sqlprefix += "`comment_url`, "
86 97 sqlprefix += "`created_time`, "
87 98 sqlprefix += "`loging_time`, "
88 99  
... ... @@ -90,6 +101,8 @@
90 101 sqlvalues += c_id + ", "
91 102 sqlvalues += "'" + insight.getContentType() + "', "
92 103 sqlvalues += "'" + message + "', "
  104 + sqlvalues += "'" + message_url + "', "
  105 + sqlvalues += "'" + insight.getContentComment() + "', "
93 106 sqlvalues += "'" + created_time + "', "
94 107 sqlvalues += "NOW(), "
95 108