本文整理汇总了Python中tweepy.utils.parse_datetime函数的典型用法代码示例。如果您正苦于以下问题:Python parse_datetime函数的具体用法?Python parse_datetime怎么用?Python parse_datetime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_datetime函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: parse
def parse(cls, api, json):
status = cls(api)
setattr(status, "_json", json)
for k, v in json.items():
if k == "user":
user_model = getattr(api.parser.model_factory, "user") if api else User
user = user_model.parse(api, v)
setattr(status, "author", user)
setattr(status, "user", user) # DEPRECIATED
elif k == "created_at":
setattr(status, k, parse_datetime(v))
elif k == "source":
if "<" in v:
setattr(status, k, parse_html_value(v))
setattr(status, "source_url", parse_a_href(v))
else:
setattr(status, k, v)
setattr(status, "source_url", None)
elif k == "retweeted_status":
setattr(status, k, Status.parse(api, v))
elif k == "place":
if v is not None:
setattr(status, k, Place.parse(api, v))
else:
setattr(status, k, None)
else:
setattr(status, k, v)
return status
开发者ID:abhishekmm,项目名称:tweepy,代码行数:28,代码来源:models.py
示例2: parse
def parse(cls, api, json):
lst = List(api)
lst._json = json
for k, v in json.items():
if k == "user":
setattr(lst, k, User.parse(api, v))
elif k == "created_at":
setattr(lst, k, parse_datetime(v))
else:
setattr(lst, k, v)
return lst
开发者ID:cdelfosse,项目名称:tweepy,代码行数:11,代码来源:models.py
示例3: parse
def parse(cls, api, json):
user = cls(api)
for k, v in json.items():
if k == "created_at":
setattr(user, k, parse_datetime(v))
elif k == "status":
setattr(user, k, Status.parse(api, v))
elif k == "following":
# twitter sets this to null if it is false
if v is True:
setattr(user, k, True)
else:
setattr(user, k, False)
else:
setattr(user, k, v)
return user
开发者ID:SoAG,项目名称:twitterspellcheck,代码行数:16,代码来源:models.py
示例4: parse
def parse(cls, api, json):
user = cls(api)
user._json = json
for k, v in json.items():
if k == 'created_at':
setattr(user, k, parse_datetime(v))
elif k == 'status':
setattr(user, k, Status.parse(api, v))
elif k == 'following':
# twitter sets this to null if it is false
if v is True:
setattr(user, k, True)
else:
setattr(user, k, False)
else:
setattr(user, k, v)
return user
开发者ID:hlix,项目名称:tweepy,代码行数:17,代码来源:models.py
示例5: save_tweet
def save_tweet(tweetobj):
twitter_id = tweetobj["id"]
username = tweetobj["user"]["name"]
screenname = tweetobj["user"]["screen_name"]
text = tweetobj["text"]
created_at = parse_datetime(tweetobj["created_at"])
created_at = timezone.make_aware(created_at, timezone=pytz.UTC) # tweets are stored int UTC
image_urls = []
try:
for media in tweetobj["entities"]["media"]:
if media["type"] == "photo":
image_urls.append(media["media_url"] + ":large")
# cut image url from tweet text
text = text.replace(media["url"], "")
except KeyError:
pass
# print("no picture")
# return # no picture
# if len(image_list) < 2:
# print ("less than 2 pictures" + str(len(image_list)))
# return
# create tweet
newtweet = Tweet(
twitter_id=twitter_id,
username=username,
screenname=screenname,
text=text,
created_at=created_at,
from_twitter=True,
)
newtweet.save()
if image_urls:
for image_url in image_urls:
# print(image_url)
image = retrieve_image(image_url)
image = process_image(image) # returns jpg
image_name = "tmp.jpg" # will be renamed by model save function
newpic = TweetPic()
newpic.tweet = newtweet
newpic.picture.save(image_name, image)
newpic.save()
generate_all_aliases(newpic.picture, include_global=True) # create thumbnails
print("saved tweet with id %s" % (str(twitter_id)))
开发者ID:vchrisb,项目名称:django-apps,代码行数:46,代码来源:tasks.py
示例6: parse_follow_unfollow_event
def parse_follow_unfollow_event(self, data):
"""
if data is follow or unfollow event-object then return parsed event-object,
else return False.
"""
if '"event":"follow"' not in data and '"event":"unfollow"' not in data:
return False
jobj = json.loads(data)
if 'event' not in jobj or 'created_at' not in jobj or 'target' not in jobj:
return False
event_name = jobj['event']
if event_name != 'follow' and event_name != 'unfollow':
return False
target = User.parse(self.api, jobj['target'])
if event_name == 'follow' and target.id == self.my_id: # User is followed
return False
created_at = parse_datetime(jobj['created_at'])
return dict(event_name=event_name, created_at=created_at, target=target)
开发者ID:cloverrose,项目名称:ProfileListener,代码行数:18,代码来源:profilelistener.py
示例7: parse_status_event
def parse_status_event(self, data):
"""
if status contains user-object then return parsed user-object,
else return False.
** NOTE **
this method treats tweet and RT,
but other data also contains '"in_reply_to_status_id":', e.g. fav.
"""
if '"in_reply_to_status_id":' not in data:
return False
jobj = json.loads(data)
if 'user' not in jobj or 'created_at' not in jobj:
return False
user = User.parse(self.api, jobj['user'])
if user.id != self.my_id and user.id not in self.friends:
return False
created_at = parse_datetime(jobj['created_at'])
return dict(user=user, created_at=created_at)
开发者ID:cloverrose,项目名称:ProfileListener,代码行数:19,代码来源:profilelistener.py
示例8: parse
def parse(cls, api, json):
status = cls(api)
for k, v in json.items():
if k == 'user':
user = User.parse(api, v)
setattr(status, 'author', user)
setattr(status, 'user', user) # DEPRECIATED
elif k == 'created_at':
setattr(status, k, parse_datetime(v))
elif k == 'source':
if '<' in v:
setattr(status, k, parse_html_value(v))
setattr(status, 'source_url', parse_a_href(v))
else:
setattr(status, k, v)
elif k == 'retweeted_status':
setattr(status, k, Status.parse(api, v))
else:
setattr(status, k, v)
return status
开发者ID:lupino3,项目名称:answr,代码行数:20,代码来源:models.py
示例9: parse
def parse(cls, api, json):
event = cls(api)
for k, v in json.items():
if k == 'target':
user_model = getattr(api.parser.model_factory, 'user')
user = user_model.parse(api, v)
setattr(event, 'target', user)
elif k == 'source':
user_model = getattr(api.parser.model_factory, 'user')
user = user_model.parse(api, v)
setattr(event, 'source', user)
elif k == 'created_at':
setattr(event, k, parse_datetime(v))
elif k == 'target_object':
setattr(event, 'target_object', v)
elif k == 'event':
setattr(event, 'event', v)
else:
setattr(event, k, v)
return event
开发者ID:Zarkonnen,项目名称:crowdpee,代码行数:20,代码来源:crowdbot.py
示例10: save_tweet
def save_tweet(tweetobj):
twitter_id = tweetobj['id']
username = tweetobj['user']['name']
screenname = tweetobj['user']['screen_name']
text = tweetobj['text']
created_at = parse_datetime(tweetobj['created_at'])
created_at = timezone.make_aware(created_at, timezone=pytz.UTC) #tweets are stored int UTC
image_urls = []
try:
for media in tweetobj['entities']['media']:
if media['type'] == 'photo':
image_urls.append(media['media_url'] + ":large")
# cut image url from tweet text
text = text.replace(media['url'],"")
except KeyError:
pass
# print("no picture")
# return # no picture
# if len(image_urls) < 2:
# print ("less than 2 pictures" + str(len(image_urls)))
# return
# create tweet
newtweet, created = Tweet.objects.get_or_create(twitter_id=twitter_id, username=username, screenname=screenname, text=text, created_at=created_at, from_twitter=True)
if created:
if image_urls:
for image_url in image_urls:
image = retrieve_image(image_url)
image = process_image(image) # returns jpg
image_name = "tmp.jpg" # will be renamed by model save function
newpic = TweetPic()
newpic.tweet = newtweet
newpic.picture.save(image_name,image,save=False)
newpic.save()
print("saved tweet with id %s" %(str(twitter_id)))
else:
print(" tweet with id %s already exists" %(str(twitter_id)))
开发者ID:hdaube,项目名称:emc_phoenix2,代码行数:38,代码来源:tasks.py
注:本文中的tweepy.utils.parse_datetime函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论