74 lines
2.2 KiB
Python
74 lines
2.2 KiB
Python
|
|
import os, sys
|
||
|
|
from datetime import datetime
|
||
|
|
from dateutil import relativedelta
|
||
|
|
|
||
|
|
sys.path.append('/var/www/digisnaxx.ado/scrapers')
|
||
|
|
import dtss
|
||
|
|
dtss.getReady()
|
||
|
|
|
||
|
|
from time import sleep
|
||
|
|
from pprint import pprint as ppr
|
||
|
|
import pytz
|
||
|
|
|
||
|
|
from events.models import Organization, Scraper
|
||
|
|
import events.digitools as digitools
|
||
|
|
|
||
|
|
venue, created = Organization.objects.get_or_create(
|
||
|
|
name="Portland City Council",
|
||
|
|
city="Portand",
|
||
|
|
website="https://www.portland.gov",
|
||
|
|
is_venue=True
|
||
|
|
)
|
||
|
|
|
||
|
|
scraper,item_count_start,virtcal = digitools.getScraper(venue, 'pdx')
|
||
|
|
|
||
|
|
event_type = "Gv"
|
||
|
|
|
||
|
|
# Time Signatures
|
||
|
|
tz = pytz.timezone("US/Eastern")
|
||
|
|
DATETIME_FORMAT = '%B %d, %Y %I:%M %p'
|
||
|
|
DATETIME_FORMAT_2 = '%B %d, %Y'
|
||
|
|
|
||
|
|
def get_events(ps, event_type):
|
||
|
|
print("Getting events ...")
|
||
|
|
contents = ps.xpath('.//*/div[@class="row position-relative"]')
|
||
|
|
ppr(contents)
|
||
|
|
for c in contents:
|
||
|
|
try:
|
||
|
|
event = {}
|
||
|
|
event['scraper'] = scraper
|
||
|
|
event['calendars'] = [scraper.calendar]
|
||
|
|
event['title'] = c.xpath('.//*/h2[@class="h4"]/a/span/text()')[0]
|
||
|
|
event['link'] = venue.website + c.xpath('.//*/h2[@class="h4"]/a/@href')[0]
|
||
|
|
event['date'] = c.xpath('.//*/time/text()')[0]
|
||
|
|
event['time'] = c.xpath('.//*/span[@class="pe-4"]/text()')[0].replace("\n", "").strip()
|
||
|
|
# event['time2'] = c.xpath('.//*/span[@class="pe-4"]/text()')
|
||
|
|
try:
|
||
|
|
event['dateStamp'] = datetime.strptime(event['date']+" "+event['time'], DATETIME_FORMAT)
|
||
|
|
except:
|
||
|
|
event['dateStamp'] = datetime.strptime(event['date'], DATETIME_FORMAT_2)
|
||
|
|
|
||
|
|
|
||
|
|
# ppr(event)
|
||
|
|
digitools.createBasicEvent(event, event_type, venue)
|
||
|
|
scraper.items+=1
|
||
|
|
except Exception as e:
|
||
|
|
print(e)
|
||
|
|
ppr(event)
|
||
|
|
print("\n\n+++\n\n")
|
||
|
|
|
||
|
|
if len(sys.argv) >= 2:
|
||
|
|
arg1 = sys.argv[1]
|
||
|
|
br = digitools.getBrowser(arg1)
|
||
|
|
else:
|
||
|
|
print("No run_env")
|
||
|
|
quit()
|
||
|
|
|
||
|
|
for n in range(3):
|
||
|
|
link = venue.website + "/auditor/council-clerk/events?page=" + str(n)
|
||
|
|
ps = digitools.getSource(br, link)
|
||
|
|
get_events(ps, "Gv")
|
||
|
|
sleep(2)
|
||
|
|
|
||
|
|
digitools.updateScraper(scraper, item_count_start)
|
||
|
|
br.close()
|