-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
196a333
commit d1c1bb6
Showing
3 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import urllib.request, urllib.parse, urllib.error | ||
import json | ||
import ssl | ||
|
||
api_key = False | ||
# If you have a Google Places API key, enter it here | ||
# api_key = 'AIzaSy___IDByT70' | ||
# https://developers.google.com/maps/documentation/geocoding/intro | ||
|
||
if api_key is False: | ||
api_key = 42 | ||
serviceurl = 'http://py4e-data.dr-chuck.net/json?' | ||
else : | ||
serviceurl = 'https://maps.googleapis.com/maps/api/geocode/json?' | ||
|
||
# Ignore SSL certificate errors | ||
ctx = ssl.create_default_context() | ||
ctx.check_hostname = False | ||
ctx.verify_mode = ssl.CERT_NONE | ||
|
||
while True: | ||
address = input('Enter location: ') | ||
if len(address) < 1: break | ||
|
||
parms = dict() | ||
parms['address'] = address | ||
if api_key is not False: parms['key'] = api_key | ||
url = serviceurl + urllib.parse.urlencode(parms) | ||
|
||
print('Retrieving', url) | ||
uh = urllib.request.urlopen(url, context=ctx) | ||
data = uh.read().decode() | ||
print('Retrieved', len(data), 'characters') | ||
|
||
try: | ||
js = json.loads(data) | ||
except: | ||
js = None | ||
|
||
if not js or 'status' not in js or js['status'] != 'OK': | ||
print('==== Failure To Retrieve ====') | ||
print(data) | ||
continue | ||
|
||
print(json.dumps(js, indent=4)) | ||
|
||
lat = js['results'][0]['geometry']['location']['lat'] | ||
lng = js['results'][0]['geometry']['location']['lng'] | ||
print('lat', lat, 'lng', lng) | ||
place_id = js['results'][0]['place_id'] | ||
print(place_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
import urllib.request,urllib.parse,urllib.error | ||
import json | ||
|
||
|
||
import ssl | ||
#ignore ssl certificate errrors | ||
ctx=ssl.create_default_context() | ||
ctx.check_hostname=ssl.CERT_NONE | ||
|
||
#url=input('Enter- ') | ||
url='https://py4e-data.dr-chuck.net/comments_1941001.json' | ||
uh=urllib.request.urlopen(url) | ||
data=uh.read().decode() | ||
print('Retrieved',len(data),'characters') | ||
try: | ||
js=json.loads(data) | ||
except: | ||
js=None | ||
|
||
|
||
comments=js['comments'] | ||
print('Count',len(comments)) | ||
count=0 | ||
for i in range(0,len(comments)): | ||
count=count+comments[i]['count'] | ||
print('Sum',count) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py | ||
#py get-pip.py | ||
#py -m pip help | ||
#pip install beautifulsoup4cd | ||
import urllib.request,urllib.parse,urllib.error | ||
import xml.etree.ElementTree as ET | ||
|
||
from bs4 import BeautifulSoup | ||
import ssl | ||
#ignore ssl certificate errrors | ||
ctx=ssl.create_default_context() | ||
ctx.check_hostname=ssl.CERT_NONE | ||
|
||
url=input('Enter- ') | ||
#url='http://py4e-data.dr-chuck.net/comments_42.html' | ||
xml=urllib.request.urlopen(url,context=ctx).read() | ||
xmlParse=ET.fromstring(xml) | ||
dataTree=xmlParse.findall('comments/comment') | ||
print('Retrieved',len(xml),'characters') | ||
print('Count:',len(dataTree)) | ||
|
||
sum=0 | ||
for tree in dataTree: | ||
c=tree.find('count').text | ||
sum=sum+int(c) | ||
print('Sum:',sum) | ||
|