Skip to content

Instantly share code, notes, and snippets.

@ssaunier
Created January 15, 2020 09:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssaunier/f2eb82912885cac33233b17571162424 to your computer and use it in GitHub Desktop.
Save ssaunier/f2eb82912885cac33233b17571162424 to your computer and use it in GitHub Desktop.
import requests
isbn = input("ISBN?")
key = f"ISBN:{isbn}"
# https://openlibrary.org/api/books?bibkeys=ISBN:0451526538&format=json&jscmd=data
url = "https://openlibrary.org/api/books"
params = {
"bibkeys": key,
"format": "json",
"jscmd": "data"
}
r = requests.get(url, params=params)
print(type(r.text))
# book = r.json()
# print(book[key]['title'])

5 routes magiques

==== Tripadvisor API

Restful:

CRUD

GET /restaurants => Renvoie une liste des restos (paginé) GET /restaurants/:id => Renvoie un resto (e.g. /restaurants/42) POST /restaurants => Crée un resto (Body) PATCH /restaurants/:id => Met à jour un resto (Body) DELETE /restaurants/:id => Supprime un resto

import csv
# with open('data/biostats.csv') as csvfile:
# reader = csv.reader(csvfile, skipinitialspace=True)
# for row in reader:
# print(row)
with open('data/biostats.csv') as csvfile:
reader = csv.DictReader(csvfile, skipinitialspace=True)
for row in reader:
# row is a collections.OrderedDict
print(row)
# print(row['Name'], row['Sex'], int(row['Age']))
beatles = [
{ 'first_name': 'John', 'last_name': 'lennon', 'instrument': 'guitar'},
{ 'first_name': 'Ringo', 'last_name': 'Starr', 'instrument': 'drums'}
]
import csv
with open('data/beatles.csv', 'w') as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=beatles[0].keys())
writer.writeheader()
for beatle in beatles:
writer.writerow(beatle)
import requests
url = 'https://api.github.com/users/ssaunier'
response = requests.get(url).json()
# print(type(response))
print(response['id'])
import requests
from bs4 import BeautifulSoup
headers = {
'Accept-Language': 'en-GB'
}
url = "https://www.imdb.com/list/ls055386972/"
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.content, "html.parser")
durations = []
for movie in soup.find_all(class_="lister-item-content"):
title = movie.find("h3").find("a").string
duration = int(movie.find(class_="runtime").string.strip(' min'))
durations.append(duration)
print(f"{title} - {duration}")
print(f"Average duration: {sum(durations) / len(durations)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment