You are on page 1of 4

Tarea 3

Segunda parte
1.
Método 1 usando Mongo import
from pymongo import MongoClient
client = MongoClient()
db = client.mongolab
rest = db.restaurants
res = rest.find({"borough":{'$in':["Staten Island","Queens"]}},
{"restaurant_id":1,"name":2})
for q in res[0:2]:
print(q)

Método 1 usando Pandas

import pandas as pd
pd.read_json("restaurants.json",lines=True)

2.
import requests, json
people = requests.get('http://api.open-notify.org/iss-pass.json?
lat=45.0&lon=-122.3&alt=20&n=10&callback=')
#people_json = people.json()
people_json = json.loads(people.text)
print(len(people_json))
print(people_json)
print(type(people_json))
total = 0
for p in people_json['response']:
dur = int(p['duration'])
print(dur, 'segundos')
total += dur
print('El tiempo total es:',total, 'segundos')

3.
import requests
from bs4 import BeautifulSoup
url = 'https://www.imdb.com/list/ls024149810/'
r = requests.get(url)
soup = BeautifulSoup(r.content, 'html.parser')

movie_gross = []
gross = soup.find_all('span',{'name':'nv'})
count = 0

for g in gross:
if count % 2 != 0:
movie_gross.append(g.text.strip())
count += 1
from re import split
total=0
for e in movie_gross:
result = ''.join([i for i in e if i.isdigit() and '.'])
r=int(result)/100
total+=r
print('El total es: $',total,'M')

You might also like