本文整理汇总了Python中store.Store.remember_photo方法的典型用法代码示例。如果您正苦于以下问题:Python Store.remember_photo方法的具体用法?Python Store.remember_photo怎么用?Python Store.remember_photo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类store.Store
的用法示例。
在下文中一共展示了Store.remember_photo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Autofriend
# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import remember_photo [as 别名]
class Autofriend(TwitterBot):
def bot_init(self):
############################
# REQUIRED: LOGIN DETAILS! #
############################
self.config['api_key'] = os.environ['TWITTER_API_KEY']
self.config['api_secret'] = os.environ['TWITTER_API_SECRET']
self.config['access_key'] = os.environ['TWITTER_ACCESS_KEY']
self.config['access_secret'] = os.environ['TWITTER_ACCESS_SECRET']
######################################
# SEMI-OPTIONAL: OTHER CONFIG STUFF! #
######################################
# how often to tweet, in seconds
self.config['tweet_interval'] = 30 * 60 # default: 30 minutes
# only include bot followers (and original tweeter) in @-replies
self.config['reply_followers_only'] = True
# fav any tweets that mention this bot?
self.config['autofav_mentions'] = False
# fav any tweets containing these keywords?
self.config['autofav_keywords'] = []
# follow back all followers?
self.config['autofollow'] = True
###########################################
# CUSTOM: your bot's own state variables! #
###########################################
self.register_custom_handler(openshift_wake_up, 60 * 60 * 12)
self.face_regions = partial(
core.face_regions,
core.load_face_detector())
self.face_recognizer = FaceRecognizer()
self.store = Store()
def get_confidence(self):
return float(os.environ.get('AUTOFRIEND_CONFIDENCE') or 50)
def on_scheduled_tweet(self):
pass
def on_follow(self, follower_id):
TwitterBot.on_follow(self, follower_id)
try:
self.store.save_friend((follower_id,))
except pg.IntegrityError:
# aborting is harmless, most likely an unfollow/refollow
self.log("tried to add duplicate twitter friend %s" % follower_id)
def _process_photo(self, friend_id, url):
with DownloadedFile(url) as downloaded:
if self.store.photo_seen(downloaded):
logging.info(
'{} tried to add duplicate photo'.format(friend_id))
else:
face_regions = self.face_regions(
core.prepare_image(downloaded))
self.face_recognizer.update(
[(face_region, friend_id)
for face_region in face_regions])
self.store.remember_photo(downloaded)
def on_direct_message(self, dm):
media = dm.entities.get('media', [])
photo = media[0] if len(media) > 0 else None
if photo:
friend_id = self.store.get_or_create_twitter_friend(
dm.sender.id)['id']
self._process_photo(friend_id, get_photo_url(photo))
self.send_direct_message(dm.sender, compliments.get_compliment())
def on_mention(self, tweet, prefix):
if 'PLEASE FORGET ME' in tweet.text.upper():
self.store.forget_friend(
self.store.get_twitter_friend(tweet.author.id))
self.api.destroy_friendship(tweet.author.id)
else:
friend_id = self.store.get_or_create_twitter_friend(
tweet.author.id)['id']
photo_urls = [get_photo_url(photo) for photo in get_photos(tweet)]
#.........这里部分代码省略.........