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 csv | |
import logging | |
def get_csv_lines(file_name, encoding='cp1251'): | |
try: | |
lines = [] | |
with open(file_name, 'rb') as f: | |
reader = csv.reader(f, delimiter=";") | |
for line in reader: | |
decoded_line = [] |
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
(?<=<h2>).+(?=</h2>) |
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
from xlrd import open_workbook | |
from xlutils.copy import copy | |
def save_workbook_copy(file_from, file_to): | |
rb = open_workbook(file_from, formatting_info=True) | |
wb = copy(rb) # a writable copy (I can't read values out of this, only write to it) | |
w_sheet = wb.get_sheet(0) # the sheet to write to within the writable copy | |
row_index = 0 | |
col_index = 0 | |
w_sheet.write(row_index, col_index,'DataToBeWritten') |
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
from xlrd import open_workbook | |
def is_row_hidden(sheet, row_n): | |
try: | |
if sheet.rowinfo_map[row_n].hidden: | |
return True | |
except KeyError: | |
# empty row, treat as hidden | |
pass |
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
from config import Session | |
from models import Person | |
session = Session() | |
persons = session.query(Person).filter(Person.name == u"Василий Пупкин", Person.status == STATUS.employer) | |
persons = session.query(Person).filter(Person.info.like(u"%Веб%")) | |
for person in persons: | |
print person.link |
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 pickle | |
with open('data.pkl', 'wb') as output: | |
pickle.dump(data1, output) | |
pickle.dump(data2, output) | |
with open('data.pkl', 'rb') as pkl_file: | |
data1 = pickle.load(pkl_file) | |
data2 = pickle.load(pkl_file) |
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
python setup.py install | |
paster create --template=spider site.ru | |
paster create --list-templates |
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
# xpath contains | |
u'//div[@class="rules"]/div[@class="inner"][contains(./div/text(), "Фотографии не найдены")]' | |
# xpath 'and' end 'exact' | |
u'//div[@id="accordion"]/table//tr[./td[1]/text()="SHAPE" and ./td[2]/text()="CARATS"]' | |
# xpath subling | |
root_elem.xpath('./following-sibling::*') | |
# xpath parent |
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
class OrderedSet(collections.MutableSet): | |
def __init__(self, iterable=None): | |
self.end = end = [] | |
end += [None, end, end] # sentinel node for doubly linked list | |
self.map = {} # key --> [key, prev, next] | |
if iterable is not None: | |
self |= iterable | |
def __len__(self): |
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
1)Создание базы для Django: | |
CREATE DATABASE database_name CHARACTER SET utf8; | |
CREATE USER 'user_name'@'localhost' IDENTIFIED BY 'user_password'; | |
GRANT ALL ON database_name.* TO 'user_name'@'localhost'; | |
2) Дамп базы | |
Сохранение: mysqldump -u имя_пользователя -p -h имя_сервера_БД имя_базы > dump.sql | |
Восстановление: mysql -u имя_пользователя -p -h имя_сервера_БД имя_базы < dump.sql |
OlderNewer