Skip to content

Instantly share code, notes, and snippets.

View serhii73's full-sized avatar
🇺🇦

Serhii A serhii73

🇺🇦
View GitHub Profile
d = {}
for email, site in zip(our_data, ALL_LINKS_ARTICLE):
d.setdefault(email, []).append(site)
@serhii73
serhii73 / Read list numbers
Created April 26, 2017 05:15
to read the list of numbers python
>>> a = list(map(int, input().split()))
>? 4 -1 4 1 1
>>> a
[4, -1, 4, 1, 1]
import argparse
PARSER = argparse.ArgumentParser('enter the directory where you want to save the data')
PARSER.add_argument("-d", "--directory", type=str,
help="where to save data? Example: /home/cat/example_folder/")
ARGS = PARSER.parse_args()
OUR_DIR = ARGS.directory
@serhii73
serhii73 / Вычитание дат
Created May 3, 2017 18:40
Отнимаем одну дату от другой
>>> from datetime import datetime, timedelta
>>> a = datetime(2010, 12, 12)
>>> b = datetime(2009, 12, 12)
>>> a-b
datetime.timedelta(365)
virtualenv -p /usr/bin/python2.7 project2_7
$ source ./<environmentname>s/bin/activate
@serhii73
serhii73 / a long string
Created May 23, 2017 08:40
a long string in python
f.write("Ranking, Code, Stock,"
"Links, Closing Price, Delta,"
"Net Purchase Amt, Buy Amt, Sell Amt, Turnover")
@serhii73
serhii73 / xpath
Created June 7, 2017 06:58
xpath. text. next page.
"//a[starts-with(descendant::text(), 'Next page')]/@href"
@serhii73
serhii73 / scrapy shell
Created June 7, 2017 07:09
scrapy shell and user-agent
from scrapy import Request
req = Request("url.com", headers={"USER-AGENT" : "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 OPR/45.0.2552.888"})
fetch(req)
@serhii73
serhii73 / get_table.py
Created June 27, 2017 20:26
Get a table in the file
#!/usr/bin/python
# -*- coding: utf-8 -*-
import requests
import pandas as pd
url = "url_with_table"
df = pd.read_html(url)
df = df[0]
df.columns = df.iloc[0]