Skip to content

Instantly share code, notes, and snippets.

@AreebaYousuf
AreebaYousuf / week_6_part_1.py
Created May 25, 2023 07:57
Extracting Data from JSON In this assignment you will write a Python program somewhat similar to http://www.py4e.com/code3/json2.py. 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 enter the sum below:…
import urllib.request, urllib.parse, urllib.error
import json
Sum=0
count=0
inp=input('Enter location:')
print('Retrieving ',inp)
uh = urllib.request.urlopen(inp)
@AreebaYousuf
AreebaYousuf / week_4 part 2.py
Created April 26, 2023 18:09
n this assignment you will write a Python program that expands on http://www.py4e.com/code3/urllinks.py. The program will use urllib to read the HTML from the data files below, extract the href= vaues from the anchor tags, scan for a tag that is in a particular position relative to the first name in the list, follow that link and repeat the proc…
import urllib.request
import urllib.parse
import urllib.error
from bs4 import BeautifulSoup
import ssl
import collections
collections.Callable = collections.abc.Callable
# Ignore SSL certificate errors
ctx = ssl.create_default_context()
@AreebaYousuf
AreebaYousuf / gist:709f45072514cc2ae13eb7be0d45e5f0
Created April 7, 2023 19:37
Finding Numbers in a Haystack In this assignment you will read through and parse a file with text and numbers. You will extract all the numbers in the file and compute the sum of the numbers. Data Files We provide two files for this assignment. One is a sample file where we give you the sum for your testing and the other is the actual data you n…
import re
fh=open('week_1.txt')
l=list()
for digits in fh:
digits=digits.rstrip()
stuff=re.findall('[0-9]+',digits)
if len(stuff)>0:
l=l+stuff
sum=0
for n in l: