This file contains hidden or 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
import urllib.request | |
import json | |
from pprint import pprint | |
url = 'https://graph.facebook.com/fmasanori' | |
resp = urllib.request.urlopen(url).read() | |
data = json.loads(resp.decode('utf-8')) | |
pprint (data) | |
This file contains hidden or 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
import urllib.request | |
import json | |
user = 'fmasanori' | |
url = 'https://graph.facebook.com/'+user+'/picture?type=large' | |
figura = urllib.request.urlopen(url).read() | |
arquivo = user + '.jpg' | |
f = open (arquivo, 'wb') | |
f.write(figura) |
This file contains hidden or 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
texto = open('alice.txt').read().lower() | |
from string import punctuation | |
for c in punctuation: | |
texto = texto.replace(c, ' ') | |
texto = texto.split() | |
dic = {} | |
for p in texto: | |
if p not in dic: | |
dic[p] = 1 | |
else: |
This file contains hidden or 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
import sqlite3 | |
con = sqlite3.connect('alunos.bd') | |
cur = con.cursor() | |
cur.execute('create table alunos(login varchar(8), ra integer)') | |
cur.execute('insert into alunos values("fmasanori", 42)') | |
cur.execute('insert into alunos values("emengarda", 666)') |
This file contains hidden or 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
import datetime | |
class Pessoa(): | |
def __init__(self, nome, nascimento): | |
self.nome = nome | |
self.nascimento = nascimento | |
def idade(self): | |
delta = datetime.date.today() - self.nascimento | |
return int(delta.days/365) | |
def __str__( self ): | |
return '%s, %d anos' %(self.nome, self.idade()) |
This file contains hidden or 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
def quicksort(v): | |
if len(v) <= 1: | |
return v | |
pivot = v[0] | |
equals = [x for x in v if x == pivot] | |
smaller = [x for x in v if x < pivot] | |
higher = [x for x in v if x > pivot] | |
return quicksort(smaller) + equals + quicksort(higher) |
This file contains hidden or 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
import urllib.request | |
import json | |
#copie o formato no exemplo e pegue o access_token | |
#em https://developers.facebook.com/tools/explorer | |
url = 'copie aqui o link Connections Friends' | |
resp = urllib.request.urlopen(url).read() | |
data = json.loads(resp.decode('utf-8')) | |
for amigo in data['data']: | |
print (amigo['name']) |
This file contains hidden or 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
#Sorry, in April 30, 2015, with Facebook 2.0 API update only friends that use the app will be show | |
import urllib.request | |
import json | |
def save_image(friend): | |
size = '/picture?width=200&height=200' | |
url = 'https://graph.facebook.com/'+ friend['id'] + size | |
image = urllib.request.urlopen(url).read() | |
f = open(friend['name'] + '.jpg', 'wb') | |
f.write(image) |
This file contains hidden or 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
#@@@@@Sorry: this code has been deprecated in 2015, April 30 with new Facebook 2.0 API version | |
import urllib.request | |
import json | |
def search(texto): | |
#pegue o access_token | |
#em https://developers.facebook.com/tools/explorer | |
url = 'https://graph.facebook.com/search?q=' | |
tail = '&type=post&access_token=<copie aqui o access_token>' | |
resp = urllib.request.urlopen(url+texto+tail).read() |
This file contains hidden or 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
import urllib.request | |
import json | |
url = 'http://www.reddit.com/r/Python/.json' | |
resp = urllib.request.urlopen(url).read() | |
parsed = json.loads(resp.decode('utf-8')) | |
for item in parsed['data']['children']: | |
doc = item['data'] |