本文整理汇总了Python中event.models.Event.end_date方法的典型用法代码示例。如果您正苦于以下问题:Python Event.end_date方法的具体用法?Python Event.end_date怎么用?Python Event.end_date使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类event.models.Event
的用法示例。
在下文中一共展示了Event.end_date方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from event.models import Event [as 别名]
# 或者: from event.models.Event import end_date [as 别名]
def handle(self, *args, **options):
print "VK parsing..."
session = vk.Session(access_token=config.VK_API_TOKEN)
api = vk.API(session, v='5.40', lang='ru', timeout=100)
fields = ['place', 'description', 'members_count',
'start_date', 'end_date']
data = api.groups.search(q=options['q'],
type='event',
fields=','.join(fields),
count=self.count,
offset=self.offset,
future=1)
pp = pprint.PrettyPrinter(indent=1)
# pp.pprint(data)
if self.length == 0:
self.length = data['count']
for item in data['items']:
#pp.pprint(item)
event = Event()
event.site = 'VK'
event.lat = item['place']['latitude'] if 'place' in item else 0
event.lng = item['place']['longitude'] if 'place' in item else 0
if event.lat*event.lng == 0 :
continue
event.start_date = dt.fromtimestamp(item['start_date'], tz=pytz.utc) \
if 'start_date' in item else None
event.end_date = dt.fromtimestamp(item['end_date'], tz=pytz.utc) \
if 'end_date' in item else event.start_date + timedelta(hours=2)
event.title = item['name']
event.ext_id = item['id']
event.photo = item['photo_200'] if 'photo_200' in item else 0
event.description = item['description'] \
if 'description' in item else ''
event.member_count = item['members_count'] \
if 'members_count' in item else 0
event.create_or_update()
"""
event = {}
event['site'] = 'VK'
event['lat'] = item['place']['latitude'] if 'place' in item else 0
event['lng'] = item['place']['longitude'] if 'place' in item else 0
if event['lat']*event['lng'] == 0 :
continue
event['start_date'] = str(dt.fromtimestamp(item['start_date'], tz=pytz.utc).strftime('YYYY-MM-DD HH:MM')) \
if 'start_date' in item else ''
event['end_date'] = str(dt.fromtimestamp(item['end_date'], tz=pytz.utc).strftime('YYYY-MM-DD HH:MM')) \
if 'end_date' in item else ''
print event['start_date']
print event['end_date']
event['title'] = item['name']
event['ext_id'] = item['id']
event['photo'] = item['photo_200'] if 'photo_200' in item else 0
event['description'] = item['description'] \
if 'description' in item else ''
event['member_count'] = item['members_count'] \
if 'members_count' in item else 0
try:
save_event, created = Event.objects.update_or_create(**event)
# print save_event.get_external_url()
except Exception, e:
print e.message
"""
if self.length > 0:
self.offset += self.count
self.length -= self.count
time.sleep(0.5)
self.handle(**options)
else:
print("VK parse ends.")
示例2: handle
# 需要导入模块: from event.models import Event [as 别名]
# 或者: from event.models.Event import end_date [as 别名]
def handle(self, *args, **options):
print "FB parsing..."
graph = facebook.GraphAPI(access_token=config.FB_API_TOKEN)
fields = [
'id',
'name',
'cover',
'description',
'start_time',
'end_time',
'place',
'attending_count',
'category',
]
data = graph.request(
"v2.5/search",
{
'q': options['q'],
'type': 'event',
'limit': self.count,
'since_date': 'currentTime',
'fields': ','.join(fields),
'after': '' if not 'after' in options else options['after'],
},
)
pp = pprint.PrettyPrinter(indent=1)
# pp.pprint(data)
for item in data['data']:
event = Event()
event.site = 'FB'
event.lat = 0
event.lng = 0
if 'place' in item:
event.lat = item['place']['location']['latitude'] \
if 'location' in item['place'] else 0
event.lng = item['place']['location']['longitude'] \
if 'location' in item['place'] else 0
if event.lat * event.lng == 0:
continue
if not 'start_time' in item:
continue
event.start_date = dateutil.parser.parse(item['start_time'])#dt.strptime(item['start_time'],'%Y-%m-%dT%H:%M:%S%Z')
event.end_date = dateutil.parser.parse(item['end_time']) \
if 'end_time' in item else event.start_date + timedelta(hours=2)
event.title = item['name']
event.ext_id = item['id']
event.photo = item['cover']['source'] \
if 'cover' in item else ''
event.description = item['description'] \
if 'description' in item else ''
event.member_count = item['attending_count'] \
if 'attending_count' in item else ''
event.category = item['category'] \
if 'category' in item else ''
event.create_or_update()
"""
event = {}
event['site'] = 'FB'
event['lat'] = 0
event['lng'] = 0
if 'place' in item:
event['lat'] = item['place']['location']['latitude'] \
if 'location' in item['place'] else 0
event['lng'] = item['place']['location']['longitude'] \
if 'location' in item['place'] else 0
if event['lat'] * event['lng'] == 0:
continue
event['start_date'] = item['start_time'] \
if 'start_time' in item else ''
event['end_date'] = item['end_time'] \
if 'end_time' in item else ''
event['title'] = item['name']
event['ext_id'] = item['id']
event['photo'] = item['cover']['source'] \
if 'cover' in item else ''
event['description'] = item['description'] \
if 'description' in item else ''
event['member_count'] = item['attending_count'] \
if 'attending_count' in item else ''
event['category'] = item['category'] \
if 'category' in item else ''
try:
save_event, created = Event.objects.update_or_create(**event)
# print save_event.get_external_url()
except Exception, e:
print e.message
pass
"""
if 'paging' in data:
# time.sleep(0.5)
options['after'] = data['paging']['cursors']['after']
self.handle(**options)
else:
print("FB parser ends.")