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
- pg_dump -U postgres -W -h localhost DATABASE_NAME > outfile | |
- psql -U postgres -W -h localhost DATABASE_NAME < infile |
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
ssh-add ~/.ssh/id_rsa |
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
python manage.py convert_to_south appname | |
python manage.py schemamigration appname --auto | |
python manage.py migrate appname | |
python manage.py migrate appname --fake 0003 |
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
python manage.py dumpdata --indent=4 > initial_data.json |
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
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 |
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
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 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 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 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 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 |