Skip to content

Instantly share code, notes, and snippets.

View kidig's full-sized avatar
☮️
Make code! Not war!

DmitrII Gerasimenko kidig

☮️
Make code! Not war!
  • Toronto, Canada
View GitHub Profile
#!/usr/bin/env python
# coding: utf-8
import re
import requests
from bottle import route, run, response
from bs4 import BeautifulSoup, Comment, Doctype
SITE_URL = 'http://habrahabr.ru'
HOST = 'localhost'
@kidig
kidig / shovel.py
Last active August 29, 2015 14:04
Example for the python shovel.
from shovel import task
@task
def hello(name):
print "Hello, %s!" % name
@task
def kwargs(**kwargs):
print "Kwargs: %s" % kwargs
@kidig
kidig / parse_schedule.py
Created April 4, 2014 11:29
Parse timetable from mosgortrans.org/pass3/
def parse_schedule_page(content):
doc = lxml.html.document_fromstring(content)
rows = doc.xpath('//table[@class="reqform"]/tr/td')
print "Rows:", len(rows)
description = ''
if len(rows):
description = " ".join([line.text_content().strip() for line in rows[0].xpath('.//h3')])
# n) Something text or
# n) Right text*
match = re.match(r'^\w\)\s+(.[^\*]*)(\*?)$', line, re.UNICODE)
if match and len(match.groups()):
answer = dict(zip(['text','right'], [x for x in match.groups() if len(x)]))