Skip to content

Instantly share code, notes, and snippets.

@manichabba
manichabba / xmlscraping.py
Created August 19, 2016 14:39
Extracting Data from XML: The program will prompt for a URL, read the XML data from that URL using urllib and then parse and extract the comment counts from the XML data, compute the sum of the numbers in the file.
import urllib #importing urllib
import xml.etree.ElementTree as ET #importing xml library
url = raw_input("Enter the URL:") #requesting a xml file
#read the file and get the comment tag
data = urllib.urlopen(url).read()
tree = ET.fromstring(data)
lst = tree.findall('.//comment')
@manichabba
manichabba / jsonscraping.py
Created August 20, 2016 01:17
====Extracting Data from JSON: ==== The program will prompt for a URL, read the JSON data from that URL using urllib and then parse and extract the comment counts from the JSON data, compute the sum of the numbers in the file and provide the sum.
import urllib #importing urllib
import json #importing json
#requesting a json file url
url = raw_input("Enter the URL:")
#load json file as list -info
info = json.loads(urllib.urlopen(url).read())
x = 0
#loop through each item in list comments
@manichabba
manichabba / geoJSON.py
Created August 20, 2016 03:21
=====Calling a JSON API=====The program will prompt for a location, contact a web service and retrieve JSON for the web service and parse that data, and retrieve the first place_id from the JSON. A place ID is a textual identifier that uniquely identifies a place as within Google Maps.
import urllib
import json
serviceurl = 'http://python-data.dr-chuck.net/geojson?'
while True:
address = raw_input('Enter location: ')
if len(address) < 1 : break
@manichabba
manichabba / Sqlite.py
Created August 23, 2016 20:45
Counting Organizations This application will read the mailbox data (mbox.txt) count up the number email messages per organization (i.e. domain name of the email address) using a database with the following schema to maintain the counts.
import re
import sqlite3
conn = sqlite3.connect('emaildb.sqlite')
cur = conn.cursor()
cur.execute('''
DROP TABLE IF EXISTS Counts''')
import xml.etree.ElementTree as ET
import sqlite3
conn = sqlite3.connect('trackdb.sqlite')
cur = conn.cursor()
# Make some fresh tables using executescript()
cur.executescript('''
DROP TABLE IF EXISTS Artist;
DROP TABLE IF EXISTS Genre;
import json
import sqlite3
conn = sqlite3.connect('rosterdb.sqlite')
cur = conn.cursor()
# Do some setup
cur.executescript('''
DROP TABLE IF EXISTS User;
DROP TABLE IF EXISTS Member;