Files
scrapers/Working/venues/getMaps.py

73 lines
1.7 KiB
Python
Raw Normal View History

2026-02-19 22:49:47 -05:00
import os, sys
from datetime import datetime, timedelta
from dateutil import relativedelta
from pprint import pprint as ppr
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 selenium.webdriver.common.by import By
from events.models import Organization, Scraper, Calendar, Event
import events.digitools as digitools
import re
def getSite(br, website, org):
ps = digitools.getSource(br, website)
links = ps.xpath('.//*/div[@class="luibr"]/div/div/a/@href')
ppr(links)
nsite = "https://www.google.com"
if len(links) > 0:
nlink = nsite + links[0]
org.barrio = nlink
org.save()
sleep(5)
if len(sys.argv) >= 2:
arg1 = sys.argv[1]
br = digitools.getBrowser(arg1)
else:
print("No run_env")
br.close()
quit()
orgs = Organization.objects.all()
# for org in orgs:
# try:
# if len(org.city) > 0:
# msg = org.name.split(" ") + org.city.split(" ")
# site = "https://www.google.com/search?q=google+maps+" + "+".join(msg)
# print(site)
# getSite(br, site, org)
# except Exception as e:
# ppr(org)
# print(e)
for org in orgs[5:]:
try:
br.get(org.barrio)
org.gmap_link = org.barrio
sleep(5)
current_url = br.current_url
match = re.search(r'@(-?\d+\.\d+),(-?\d+\.\d+)', current_url)
print(match[1], match[0].split(",")[1])
org.latitude = match[1].strip()
org.longitude = match[0].split(",")[1].strip()
org.save()
except Exception as e:
ppr(org)
print(e)
br.close()