当前位置: 首页>>代码示例>>Python>>正文


Python Event.member_count方法代码示例

本文整理汇总了Python中event.models.Event.member_count方法的典型用法代码示例。如果您正苦于以下问题:Python Event.member_count方法的具体用法?Python Event.member_count怎么用?Python Event.member_count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在event.models.Event的用法示例。


在下文中一共展示了Event.member_count方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle

# 需要导入模块: from event.models import Event [as 别名]
# 或者: from event.models.Event import member_count [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.")
开发者ID:eivae2iz,项目名称:hakaton-events,代码行数:75,代码来源:vk_events.py

示例2: handle

# 需要导入模块: from event.models import Event [as 别名]
# 或者: from event.models.Event import member_count [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.")
开发者ID:eivae2iz,项目名称:hakaton-events,代码行数:97,代码来源:fb_events.py


注:本文中的event.models.Event.member_count方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。