This file contains 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 math | |
from datetime import timedelta, datetime | |
def get_time(callable_stuff, tries=10): | |
deltas = [] | |
for _ in range(tries): | |
now = datetime.now() | |
callable_stuff() | |
deltas.append(datetime.now() - now) |
This file contains 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 requests | |
from bs4 import BeautifulSoup | |
def get_product_info_from_website(sku): | |
host = 'https://www.linio.com.mx' | |
search_page_text = requests.get('%s/search' % host, params={'q': sku}).text | |
page = BeautifulSoup(search_page_text) | |
url = page.find('div', {'class': 'catalog-product-title'}) | |
if not url: |
This file contains 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 os | |
import string | |
import itertools | |
from datetime import datetime | |
import elaphe | |
def create_dirs(): | |
if not os.path.exists('data'): |
This file contains 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
SELECT | |
name, | |
count(*) as msg_count | |
FROM users | |
JOIN messages on users.uid = messages.uid | |
GROUP BY users.uid; |
This file contains 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 zip_long(keys, values): | |
""" Версия zip, которая не удаляет лишние ключи, а оставляет их со значениями None""" | |
values += [None] * (len(keys) - len(values)) | |
return dict(zip(keys, values)) | |
def test_zip_long(): | |
""" Тестирование для бедных. | |
При запуске выполнит тестирование функции zip_long и вернет True если тесты прошли | |
(иначе выкинет AssetrionError). |
This file contains 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
from hammock import Hammock as Github | |
github = Github('https://api.github.com') | |
headers = {'Accept': 'application/vnd.github.preview'} | |
resp = github.search.repositories.GET(params={'q': 'language:python', 'sort': 'stars', 'per_page': 10, 'page': 1}, headers=headers) | |
res = resp.json() | |
print res['items'][0]['full_name'] | |
print len(res['items']) |