Fix publish to get tags from spider
This commit is contained in:
parent
a4a9b17c2d
commit
9f8f114c53
2 changed files with 21 additions and 8 deletions
|
@ -32,13 +32,16 @@ class Event(peewee.Model):
|
||||||
}
|
}
|
||||||
|
|
||||||
place_id_by_location = {
|
place_id_by_location = {
|
||||||
"Teatro Polytheama": (1, "polytheama"),
|
"Teatro Polytheama": 1,
|
||||||
"Sala Glória Rocha do Centro das Artes": (3, "gloria-rocha"),
|
"Sala Glória Rocha do Centro das Artes": 3,
|
||||||
}
|
}
|
||||||
place_id, tag = place_id_by_location.get(self.location) or (None, None)
|
place_id = place_id_by_location.get(self.location)
|
||||||
if place_id:
|
if place_id:
|
||||||
payload["place_id"] = place_id
|
payload["place_id"] = place_id
|
||||||
payload["tags"] = ["jundiaí", tag]
|
|
||||||
|
tags = self.tags.split(",")
|
||||||
|
if tags:
|
||||||
|
payload["tags"] = tags
|
||||||
|
|
||||||
with open(f"{settings.IMAGES_STORE}{self.image_path}", "rb") as image_file:
|
with open(f"{settings.IMAGES_STORE}{self.image_path}", "rb") as image_file:
|
||||||
files = {"image": image_file}
|
files = {"image": image_file}
|
||||||
|
|
|
@ -24,15 +24,25 @@ class CulturaJundiaiSpider(scrapy.Spider):
|
||||||
end_time = date_search.groupdict()["end_time"]
|
end_time = date_search.groupdict()["end_time"]
|
||||||
end_datetime = datetime.strptime(f"{date} {end_time}", "%d/%m/%Y %H:%M")
|
end_datetime = datetime.strptime(f"{date} {end_time}", "%d/%m/%Y %H:%M")
|
||||||
|
|
||||||
|
tags = "jundiaí"
|
||||||
|
location = event.css(".resumo-lista::text").get()
|
||||||
|
tag_by_location = (
|
||||||
|
{
|
||||||
|
"Teatro Polytheama": "polytheama",
|
||||||
|
"Sala Glória Rocha do Centro das Artes": "gloria-rocha",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
tag = tag_by_location.get(location)
|
||||||
|
if tag:
|
||||||
|
tags.append(tag)
|
||||||
|
|
||||||
event_data = {
|
event_data = {
|
||||||
"title": event.css(".titulo-lista::text").get(),
|
"title": event.css(".titulo-lista::text").get(),
|
||||||
"start_datetime": start_datetime,
|
"start_datetime": start_datetime,
|
||||||
"end_datetime": end_datetime,
|
"end_datetime": end_datetime,
|
||||||
"url": event.css("a::attr(href)").get(),
|
"url": event.css("a::attr(href)").get(),
|
||||||
"location": event.css(".resumo-lista::text").get(),
|
"location": location,
|
||||||
"tags": [
|
"tags": tags,
|
||||||
"jundiaí",
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
yield scrapy.Request(
|
yield scrapy.Request(
|
||||||
event_data["url"],
|
event_data["url"],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue