本文整理汇总了Python中pocket.Pocket.add方法的典型用法代码示例。如果您正苦于以下问题:Python Pocket.add方法的具体用法?Python Pocket.add怎么用?Python Pocket.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocket.Pocket
的用法示例。
在下文中一共展示了Pocket.add方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: form_valid
# 需要导入模块: from pocket import Pocket [as 别名]
# 或者: from pocket.Pocket import add [as 别名]
def form_valid(self, form):
pocket_instance = Pocket(settings.CONSUMER_KEY, self.request.session['access_token'])
file = self.request.FILES['file']
for url in file.readlines():
pocket_instance.add(url.decode().rstrip())
# pocket_instance.bulk_add(item_id='', url=url.decode().rstrip())
# pocket_instance.commit()
return super(HomeView, self).form_valid(form)
示例2: push_to_pocket
# 需要导入模块: from pocket import Pocket [as 别名]
# 或者: from pocket.Pocket import add [as 别名]
def push_to_pocket(link_id):
link = Document.find_one({'user': g.user._id, '_id': ObjectId(link_id)})
if link:
user = User.find_one({'_id': link.user})
pocket_instance = Pocket(POCKET_APP_TOKEN,
user.credentials['pocket']['token'])
pocket_instance.add(link.url, wait=False)
link.read = True
link.save()
return "OK"
示例3: add_item
# 需要导入模块: from pocket import Pocket [as 别名]
# 或者: from pocket.Pocket import add [as 别名]
def add_item(item):
if item is not None:
access_token = wf.get_password('pocket_access_token')
pocket_instance = Pocket(config.CONSUMER_KEY, access_token)
try:
pocket_instance.add(
url=item['url'], title=item['title'], tags="alfred")
return True
except InvalidQueryException:
pass
return False
示例4: send_to_pocket
# 需要导入模块: from pocket import Pocket [as 别名]
# 或者: from pocket.Pocket import add [as 别名]
def send_to_pocket(url):
if mconfig:
if 'share_settings' in mconfig:
if 'pocket' in mconfig['share_settings']:
pocket_config = mconfig['share_settings']['pocket']
pc = Pocket(
consumer_key=pocket_config['consumer_key'],
access_token=pocket_config['access_token']
)
return pc.add( url=url )
else:
return {"status":0,"message":"Pocket not configured."}
else:
return {"status":0,"message":"No configuration file found."}
示例5: add_url
# 需要导入模块: from pocket import Pocket [as 别名]
# 或者: from pocket.Pocket import add [as 别名]
def add_url(url, tag):
print 'adding', url
pocket_instance = Pocket(consumer_key, access_token)
print pocket_instance.add(url=url, tags=[tag])
示例6: ServicePocket
# 需要导入模块: from pocket import Pocket [as 别名]
# 或者: from pocket.Pocket import add [as 别名]
class ServicePocket(ServicesMgr):
def __init__(self, token=None):
super(ServicePocket, self).__init__(token)
self.consumer_key = settings.TH_POCKET['consumer_key']
self.token = token
if token:
self.pocket = Pocket(self.consumer_key, token)
def read_data(self, **kwargs):
"""
get the data from the service
as the pocket service does not have any date
in its API linked to the note,
add the triggered date to the dict data
thus the service will be triggered when data will be found
:param kwargs: contain keyword args : trigger_id at least
:type kwargs: dict
:rtype: list
"""
trigger_id = kwargs['trigger_id']
date_triggered = kwargs['date_triggered']
data = list()
# pocket uses a timestamp date format
since = int(
time.mktime(datetime.datetime.timetuple(date_triggered)))
if self.token is not None:
# get the data from the last time the trigger have been started
# timestamp form
pockets = self.pocket.get(since=since, state="unread")
content = ''
if pockets is not None and len(pockets[0]['list']) > 0:
for my_pocket in pockets[0]['list'].values():
if my_pocket['excerpt']:
content = my_pocket['excerpt']
elif my_pocket['given_title']:
content = my_pocket['given_title']
my_date = arrow.get(str(date_triggered),
'YYYY-MM-DD HH:mm:ss')\
.to(settings.TIME_ZONE)
data.append({'my_date': str(my_date),
'tag': '',
'link': my_pocket['given_url'],
'title': my_pocket['given_title'],
'content': content,
'tweet_id': 0})
cache.set('th_pocket_' + str(trigger_id), data)
return data
def process_data(self, **kwargs):
"""
get the data from the cache
:param kwargs: contain keyword args : trigger_id at least
:type kwargs: dict
"""
kw = {'cache_stack': 'th_pocket',
'trigger_id': str(kwargs['trigger_id'])}
return super(ServicePocket, self).process_data(**kw)
def save_data(self, trigger_id, **data):
"""
let's save the data
:param trigger_id: trigger ID from which to save data
:param data: the data to check to be used and save
:type trigger_id: int
:type data: dict
:return: the status of the save statement
:rtype: boolean
"""
from th_pocket.models import Pocket as PocketModel
status = False
if self.token and 'link' in data and data['link'] is not None\
and len(data['link']) > 0:
# get the pocket data of this trigger
trigger = PocketModel.objects.get(trigger_id=trigger_id)
title = self.set_title(data)
# convert htmlentities
title = HtmlEntities(title).html_entity_decode
try:
self.pocket.add(
url=data['link'], title=title, tags=(trigger.tag.lower()))
sentence = str('pocket {} created').format(data['link'])
logger.debug(sentence)
status = True
except Exception as e:
logger.critical(e)
status = False
#.........这里部分代码省略.........
示例7: print
# 需要导入模块: from pocket import Pocket [as 别名]
# 或者: from pocket.Pocket import add [as 别名]
from pocket import Pocket
ckey = '47167-9324a229a155827bc214aa2a'
redir = 'http://google.com'
request_token = Pocket.get_request_token(consumer_key=ckey, redirect_uri=redir)
# URL to redirect user to, to authorize your app
auth_url = Pocket.get_auth_url(code=request_token, redirect_uri=redir)
print(auth_url)
input()
user_credentials = Pocket.get_credentials(consumer_key=ckey, code=request_token)
access_token = user_credentials['access_token']
pocketi = Pocket(ckey, access_token)
for link in links[500:]:
pocketi.add(link)
import numpy as np
import matplotlib.pyplot as plt
xaxis = range(1,50)
plt.plot(xaxis, [np.sqrt(6*sum([1./n**2 for n in range(1,x)])) for x in xaxis])
plt.axhline(np.pi, color='r')
plt.show()z
示例8: ServicePocket
# 需要导入模块: from pocket import Pocket [as 别名]
# 或者: from pocket.Pocket import add [as 别名]
class ServicePocket(ServicesMgr):
def __init__(self, token=None):
self.consumer_key = settings.TH_POCKET['consumer_key']
if token:
self.pocket = Pocket(self.consumer_key, token)
def read_data(self, token, trigger_id, date_triggered):
"""
get the data from the service
as the pocket service does not have any date
in its API linked to the note,
add the triggered date to the dict data
thus the service will be triggered when data will be found
:param trigger_id: trigger ID to process
:param date_triggered: the date of the last trigger
:type trigger_id: int
:type date_triggered: datetime
:return: list of data found from the date_triggered filter
:rtype: list
"""
data = list()
# pocket uses a timestamp date format
since = int(
time.mktime(datetime.datetime.timetuple(date_triggered)))
if token is not None:
# get the data from the last time the trigger have been started
# timestamp form
pockets = self.pocket.get(since=since, state="unread")
if pockets is not None and len(pockets[0]['list']) > 0:
for my_pocket in pockets[0]['list'].values():
if my_pocket['excerpt']:
content = my_pocket['excerpt']
elif my_pocket['given_title']:
content = my_pocket['given_title']
my_date = arrow.get(str(date_triggered),
'YYYY-MM-DD HH:mm:ss')\
.to(settings.TIME_ZONE)
data.append({'my_date': str(my_date),
'tag': '',
'link': pocket['given_url'],
'title': pocket['given_title'],
'content': content,
'tweet_id': 0})
cache.set('th_pocket_' + str(trigger_id), data)
return data
def process_data(self, trigger_id):
"""
get the data from the cache
:param trigger_id: trigger ID from which to save data
:type trigger_id: int
"""
return cache.get('th_pocket_' + str(trigger_id))
def save_data(self, token, trigger_id, **data):
"""
let's save the data
:param trigger_id: trigger ID from which to save data
:param **data: the data to check to be used and save
:type trigger_id: int
:type **data: dict
:return: the status of the save statement
:rtype: boolean
"""
from th_pocket.models import Pocket as PocketModel
status = False
if token and 'link' in data and data['link'] is not None\
and len(data['link']) > 0:
# get the pocket data of this trigger
trigger = PocketModel.objects.get(trigger_id=trigger_id)
title = ''
title = (data['title'] if 'title' in data else '')
# convert htmlentities
title = HtmlEntities(title).html_entity_decode
try:
self.pocket.add(
url=data['link'], title=title, tags=(trigger.tag.lower()))
sentence = str('pocket {} created').format(data['link'])
logger.debug(sentence)
status = True
except Exception as e:
logger.critical(e)
status = False
else:
logger.critical("no token provided for trigger ID %s ", trigger_id)
return status
def auth(self, request):
#.........这里部分代码省略.........
示例9: add_item
# 需要导入模块: from pocket import Pocket [as 别名]
# 或者: from pocket.Pocket import add [as 别名]
def add_item(item):
access_token = wf.get_password('pocket_access_token')
pocket_instance = Pocket(CONSUMER_KEY, access_token)
pocket_instance.add(url=item['url'], title=item['title'], tags="alfred")
示例10: __init__
# 需要导入模块: from pocket import Pocket [as 别名]
# 或者: from pocket.Pocket import add [as 别名]
class PocketApp:
DEFAULT_WORDS_PER_MINUTE = 180
REDIRECT_URL = 'http://www.google.com'
def __init__(self):
self._configs = Configs()
self._storage = Storage()
self._pocket = Pocket(
self._configs.get('consumer_key'),
self._configs.get('access_token')
)
def configure(self, consumer_key, access_token,
words_per_minute, sort_field):
self._configs.set('consumer_key', consumer_key)
self._configs.set('access_token', access_token)
self._configs.set('words_per_minute', words_per_minute)
self._configs.set('sort_field', sort_field)
self._configs.set('last_fetch', 0)
self._configs.write()
self._storage.clear()
def get_request_token(self, consumer_key):
return self._pocket.get_request_token(
consumer_key, self.REDIRECT_URL
)
def get_access_token(self, consumer_key, request_token):
return self._pocket.get_access_token(
consumer_key, request_token
)
def add_article(self, url, title=None, tags=None):
if isinstance(tags, tuple):
tags = ','.join(list(tags))
try:
return self._pocket.add(url, title, tags)
except PocketException as e:
raise_from(self._check_exception(e), e)
def get_articles(self, limit=None, order=None):
if self._storage.is_empty():
self.fetch_articles(True)
articles = self._storage.read(limit, order)
sort_field = self._configs.get('sort_field')
if not sort_field:
sort_field = 'reading_time'
articles = sorted(articles,
key=itemgetter(sort_field))
return articles
def search(self, search, state, tag, sort):
try:
articles = self._pocket.retrieve(search=search,
state=state,
tag=tag,
sort=sort)
return self._get_articles_index(articles)
except PocketException as e:
raise_from(self._check_exception(e), e)
def archive_article(self, item_id):
try:
self._pocket.archive(int(item_id)).commit()
except PocketException as e:
raise_from(self._check_exception(e), e)
def find_article(self, item_id):
index = self._storage.read()
for article in index:
if str(article['id']) == str(item_id):
return article
return None
def fetch_articles(self, output_progress=False):
spinner = None
if output_progress:
spinner = Spinner('Loading articles ')
articles_index = []
last_fetch = self._configs.get('last_fetch')
offset = 0
count = 20
while(True):
try:
articles = self._pocket.retrieve(
state='unread',
count=count,
offset=offset,
since=last_fetch
)
#.........这里部分代码省略.........
示例11: ServicePocket
# 需要导入模块: from pocket import Pocket [as 别名]
# 或者: from pocket.Pocket import add [as 别名]
class ServicePocket(ServicesMgr):
"""
Service Pocket
"""
def __init__(self, token=None, **kwargs):
super(ServicePocket, self).__init__(token, **kwargs)
self.consumer_key = settings.TH_POCKET_KEY['consumer_key']
self.token = token
self.oauth = 'oauth1'
self.service = 'ServicePocket'
if token:
try:
self.pocket = Pocket(self.consumer_key, token)
except (AuthException, RateLimitException) as e:
us = UserService.objects.get(token=token)
logger.error(e.msg, e.error_code)
update_result(us.trigger_id, msg=e.msg, status=False)
def _create_entry(self, url, title, tags):
"""
Create an entry
:param url: url to save
:param title: title to set
:param tags: tags to set
:return: status
"""
try:
self.pocket.add(url=url, title=title, tags=tags)
sentence = str('pocket {} created').format(url)
logger.debug(sentence)
status = True
except Exception as e:
logger.critical(e)
update_result(self.trigger_id, msg=e, status=False)
status = False
return status
def read_data(self, **kwargs):
"""
get the data from the service
As the pocket service does not have any date in its API linked to the note,
add the triggered date to the dict data thus the service will be triggered when data will be found
:param kwargs: contain keyword args : trigger_id at least
:type kwargs: dict
:rtype: list
"""
trigger_id = kwargs.get('trigger_id')
date_triggered = kwargs.get('date_triggered')
data = list()
# pocket uses a timestamp date format
since = arrow.get(date_triggered).timestamp
if self.token is not None:
# get the data from the last time the trigger have been started
# timestamp form
pockets = self.pocket.get(since=since, state="unread")
content = ''
if pockets is not None and len(pockets[0]['list']) > 0:
for my_pocket in pockets[0]['list'].values():
if my_pocket.get('excerpt'):
content = my_pocket['excerpt']
elif my_pocket.get('given_title'):
content = my_pocket['given_title']
my_date = arrow.get(str(date_triggered), 'YYYY-MM-DD HH:mm:ss').to(settings.TIME_ZONE)
data.append({'my_date': str(my_date),
'tag': '',
'link': my_pocket['given_url'],
'title': my_pocket['given_title'],
'content': content,
'tweet_id': 0})
# digester
self.send_digest_event(trigger_id, my_pocket['given_title'], my_pocket['given_url'])
cache.set('th_pocket_' + str(trigger_id), data)
return data
def save_data(self, trigger_id, **data):
"""
let's save the data
:param trigger_id: trigger ID from which to save data
:param data: the data to check to be used and save
:type trigger_id: int
:type data: dict
:return: the status of the save statement
:rtype: boolean
"""
if data.get('link'):
if len(data.get('link')) > 0:
# get the pocket data of this trigger
from th_pocket.models import Pocket as PocketModel
trigger = PocketModel.objects.get(trigger_id=trigger_id)
title = self.set_title(data)
# convert htmlentities
title = HtmlEntities(title).html_entity_decode
#.........这里部分代码省略.........