Ejemplo n.º 1
0
 def __init__(self, app):
     super(ContentPoster, self).__init__(name='poster')
     self.app = app
     self.daemon = True
     self.queue = Queue()
     self.plurk = PlurkAPI.fromfile('plurk.json')
     self.cache = []
     try:
         with open('cache.txt', 'r') as f:
             self.cache = [line.strip() for line in f]
     except FileNotFoundError:
         logging.warning('No cache file present')
Ejemplo n.º 2
0
#!/usr/bin/env python
from datetime import datetime, timedelta
from dateutil.parser import parse as parse_date
from dateutil.tz import tzutc, tzlocal
from plurk_oauth import PlurkAPI

class Plurk(object):
    def __init__(self, plurk_id, posted, content_raw, **kwargs):
        self.plurk_id = plurk_id
        self.posted = parse_date(posted)
        self.content_raw = content_raw
    def __hash__(self):
        return self.plurk_id

plurk = PlurkAPI.fromfile('plurk.json')
start = datetime.now(tzlocal())
end = start - timedelta(hours=24)

plurks = []
while start > end:
    print('Fetching', start)
    resp = plurk.callAPI('/APP/Timeline/getPlurks', {
        'filter': 'my',
        'limit': 30,
        'offset': start.astimezone(tzutc()).isoformat() })
    plurks.extend(Plurk(**p) for p in resp['plurks'])
    start = min(plurks, key=lambda x: x.posted).posted

titles = set()
unique_plurks = sorted(set(plurks), key=lambda x: x.posted)
print('Unique plurks', len(unique_plurks))
Ejemplo n.º 3
0
 def setUp(self):
     self.plurk = PlurkAPI.fromfile('API.keys')
     if not self.plurk.is_authorized():
         raise KeyError(
             "You need to put cunsomer/access key/secret in API.keys")
Ejemplo n.º 4
0
def time_stamp():
    localtime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    return localtime


# fixed_plurk
fixed_plurk = {
    "plurk_id": "",
    "content": "",
    "qualifier": "says", "lang": "tr_ch"
}

if __name__ == '__main__':

    # get api token
    plurk = PlurkAPI.fromfile("api.key")

    # user info
    with codecs.open("users.yaml", encoding="utf-8") as f:
        users = yaml.load(f)

    try:
        # get every plurks
        timeline_plurks = plurk.callAPI('/APP/Polling/getPlurks', options={"offset": "2019-10-26T11:48:00"})['plurks']

        # choose new plurks(plurk_type == 0) from all plurks
        unread_plurks = [unread_plurk for unread_plurk in timeline_plurks
                         if unread_plurk['plurk_type'] == 0 and unread_plurk['owner_id'] in users['ids']]

        for unread_plurk in unread_plurks:
            # replurk format
Ejemplo n.º 5
0
 def setUp(self):
     self.plurk = PlurkAPI.fromfile('API.keys')
     if not self.plurk.is_authorized():
         raise KeyError("You need to put cunsomer/access key/secret in API.keys")
Ejemplo n.º 6
0
from plurk_oauth import PlurkAPI
import json
import requests

plurk = PlurkAPI.fromfile("API.keys")
channelAddr = plurk.callAPI("/APP/Realtime/GetUserChannel").get("comet_server")[:-len("&offset=0")]
offset = 0

while True:
    callback = json.loads(requests.get(channelAddr+"&offset="+str(offset))
                          .text[len("CometChannel.scriptCallback("):-len(");")])
    newOffset = callback.get("new_offset")
    if newOffset != -1:
        tds = callback.get("data")
        for td in tds:
            print(json.dumps(td, indent=4, sort_keys=True, ensure_ascii=False))
            # TODO: stuff td in to a queue

        offset = newOffset

# example of calling plurk API
# response = plurk.callAPI('/APP/Responses/get', options={'plurk_id': 1419178662})

# comet server call back data model:
# {
#    "data": [
#       {<json>},
#       {<json>}....
#    ],
#    "new_offset": 16
# }
Ejemplo n.º 7
0
# Plurk robot
# Plurk API list: https://www.plurk.com/API
# plurk-oauth: https://github.com/clsung/plurk-oauth
import re
import json
import urllib3
from plurk_oauth import PlurkAPI

# api.keys for authen
plurk = PlurkAPI.fromfile('./api.keys')
print(plurk.callAPI('/APP/Profile/getOwnProfile'))

# the user channel can get the new plurk for the user's timeline
# only new plurk, no re-plurk, response, or the other
# only fetch new messages from a given offset. You'll get offset when a response is returned.
# offset = -1, waiting for data to be posted.
# offset = -3, offset is wrong and you need to resync your data.
comet = plurk.callAPI('/APP/Realtime/getUserChannel')
comet_channel = comet.get('comet_server') + '&new_offset=%d'
json_re = re.compile('CometChannel.scriptCallback\((.+)\);\s')
new_offset = -1

while True:
    url_get = urllib3.PoolManager()
    request = url_get.request(comet_channel % new_offset)

# get new response,