context.py 3.25 KB
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
import json
import time


class Context() :

token = ""
contents_list = []
orderlist = [529491587137957,858096217617804,1670879929842831,1406069429705944,1531526667169602,
504207933048979,813554295420159,265757330288799,270103526524526,1702892339935231,
886456498082470,167968880220563,526019510826052,153258784853075,327293184069664,
467342726674321,497899983625735,415438118555115,147088008818887,502626173152828,
117352678358122,171144389693855]

pagelist = {'529491587137957':'피키캐스트','858096217617804':'피키픽처스','1670879929842831':'피키예능촌',
'1406069429705944':'피키툰','1531526667169602':'피키키키키','504207933048979':'피키생활백서',
'265757330288799':'피키스토리','270103526524526':'곰들의반란','1702892339935231':'궁금청년',
'886456498082470':'우주인','167968880220563':'끔켬','526019510826052':'언어유희왕',
'327293184069664':'연애의모든것','467342726674321':'너눈지','497899983625735':'베스트비디오',
'415438118555115':'남자기때문에','147088008818887':'도기도기','502626173152828':'여자라면',
'117352678358122':'영화는 방울방울','171144389693855':'영화공장','813554295420159':'피키무비',
'153258784853075':'플레이'}


def __init__(self, token):
#print "context"
self.token = token.getToken()

def isNext(self,data):
if data['data'] == []:
return False
else:
return True

def nextUrl(self,data):
try:
return data['paging']['next']
except:
return ""

def setOrderList(self, list):
self.orderlist = list

def setPageList(self, dic):
self.pagelist = dic

def getPageList(self):
return self.pagelist

def getOrderList(self):
return self.orderlist


def setContextsFeed(self):

self.setContextsFeedAndTimestemp(0)

def setContextsFeedAll(self):

signed_max_int = 0x7fffffff - 1
self.setContextsFeedAndTimestemp(signed_max_int)

def setContextsFeedAndTimestemp(self,ts):

time_now = int(time.time())

return_val = []
for list in self.orderlist:
time.sleep(1)
url = 'https://graph.facebook.com/v2.5/%d/feed?'%list
txt = requests.get(url + self.token).text
data = json.loads(txt)
return_val.append(data)
#print data

while self.isNext(data):
nextUrl = self.nextUrl(data)
#print nextUrl
feed_ts = int(nextUrl.split("until=")[1].split("&")[0])
if (time_now - ts) > feed_ts :
break
txt = requests.get(nextUrl).text
data = json.loads(txt)
return_val.append(data)

self.setContentsList(return_val)

def setContentsList(self, list):
for i in list:
#print i
for j in i['data']:
self.contents_list.append(j)

def getContentsList(self):
return self.contents_list