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'] |
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 | |
| 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() | |
| data = json.loads(resp.decode('utf-8')) |
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 | |
| 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) | |
| f.close() |
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
| 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 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
| 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
| arq = open('alice.txt') | |
| texto = arq.read() | |
| texto = texto.lower() | |
| import string | |
| for c in string.punctuation: | |
| texto = texto.replace(c, ' ') | |
| texto = texto.split() | |
| dic = {} | |
| for p in texto: |
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 | |
| class Dic42(dict): | |
| def __missing__(self, key): | |
| return '42' | |
| url = 'https://graph.facebook.com/fmasanori' | |
| resp = urllib.request.urlopen(url).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 fnmatch | |
| import os | |
| imagens = ['*.jpg', '*.jpeg', '*.png', '*.tif', '*.tiff'] | |
| achados = [] | |
| for raiz, diretórios, arquivos in os.walk("C:\\"): | |
| for extensões in imagens: | |
| for arq in fnmatch.filter(arquivos, extensões): | |
| print (raiz + '\\' + arq) |