コード例 #1
0
    def map_initiative(response, item):
        initiative = InitiativeImport(
            source_id=item.id,
            source_uri=f"https://wijamsterdam.nl/initiatief/{item.id}",
            # using dateutil and not datetime because: https://stackoverflow.com/a/3908349/167131
            created_at=parser.parse(item.createdAt),
            name=item.title,
            description=f"{item.summary}"
            f"\n--------\n"
            f"{item.description}",
            group=InitiativeGroup.SUPPLY,
            extra_fields=response.content.decode("utf-8")
            # Probably better to leave email / phone empty
            # name is already tricky maybe albeit open data.
        )

        if hasattr(item.extraData, "area"):
            initiative.location = item.extraData.area
        if hasattr(item.extraData, "isOrganiserName"):
            initiative.organiser = item.extraData.isOrganiserName
        if hasattr(item.extraData, "theme"):
            initiative.category = item.extraData.theme
        if hasattr(item.extraData, "isOrganiserWebsite"):
            initiative.url = item.extraData.isOrganiserWebsite
        if hasattr(item, "position"):
            initiative.latitude = item.position.lat
            initiative.longitude = item.position.lng

        return initiative
コード例 #2
0
ファイル: coronapioniers.py プロジェクト: ictmotion/helpradar
    def complete(self, initiative: InitiativeImport):
        post_url = self.config.get_api_post_url(initiative.source_id)
        detail = self.get(post_url)

        try:
            initiative_url_guid = '75aa5e4d-fe98-4a7a-94ec-adab2f7f9b88'

            result = detail.json()
            initiative.created_at=parser.parse(result['created'])
            initiative.scraped_at=datetime.datetime.now()
            
            initiative.name=result['title']
            initiative.description=result['content']

            if initiative_url_guid in result['values']:
                initiative.url = result['values'][initiative_url_guid][0]
            
            initiative.extra_fields = self.parse_extra_fields(result)

            category_list = []
            for tag in result['tags']:
                category_list.append(self.category_dict[tag['id']])
            s = ', '
            initiative.category = s.join(category_list)

        except Exception as ex:
            msg = f"Error in complete function for initiative {initiative.source_id}"
            raise ScrapeException(msg) from ex
コード例 #3
0
ファイル: wijamsterdam.py プロジェクト: ictmotion/helpradar
    def map_initiative(item):
        org = json.dumps(item)
        initiative = InitiativeImport(
            source_id=item["id"],
            source_uri=f"https://wijamsterdam.nl/initiatief/{item['id']}",
            # using dateutil and not datetime because: https://stackoverflow.com/a/3908349/167131
            created_at=parser.parse(item["createdAt"]),
            name=item["title"],
            description=f"{item['summary']}"
            f"\n--------\n"
            f"{item['description']}",
            group=InitiativeGroup.SUPPLY,
            extra_fields=org
            # Probably better to leave email / phone empty
            # name is already tricky maybe albeit open data.
        )

        extra_data = item["extraData"]
        if "area" in extra_data:
            initiative.location = extra_data["area"]
        if "isOrganiserName" in extra_data:
            initiative.organiser = extra_data["isOrganiserName"]
        if "theme" in extra_data:
            initiative.category = extra_data["theme"]
        if "isOrganiserWebsite" in extra_data:
            initiative.url = extra_data["isOrganiserWebsite"]
        if "position" in item:
            initiative.latitude = item["position"]["lat"]
            initiative.longitude = item["position"]["lng"]

        return initiative