def getTVData(): data = netutil.getURLResponseData(S_TV_URL, encoding='utf-8') if data: elements = re.findall( r'<a href="(.+?)"><img src=.+?><span>(.+?)</span></a>', data) return elements return None
def parseTZone(url): data = netutil.getURLResponseData(url, encoding='utf-8') if data: gmt = re.search(r'<a href="/wiki/UTC.+?" title=".+?" class="mw-redirect">UTC\+(\d+)</a>', data) if gmt: tzone = gmt.group(1) return tzone return None
def parseTZone(url): data = netutil.getURLResponseData(url, encoding='utf-8') if data: gmt = re.search( r'<a href="/wiki/UTC.+?" title=".+?" class="mw-redirect">UTC\+(\d+)</a>', data) if gmt: tzone = gmt.group(1) return tzone return None
def getTimeZoneFromWorldTimeZonesRu(city): global gWorldTimeZonesRuData if not gWorldTimeZonesRuData: data = netutil.getURLResponseData('http://world-time-zones.ru/goroda.htm', encoding='windows-1251') items = re.findall(u'Часовой пояс г. (.+?)</td>.+?\(UTC\+(\d+)', data, re.DOTALL) for item in items: cityname = item[0] cityzone = item[1] gWorldTimeZonesRuData[cityname] = cityzone return gWorldTimeZonesRuData.get(city)
def getTimeZoneFromKursrubRu(city): global gKursrubRuData if not gKursrubRuData: data = netutil.getURLResponseData('http://kursrub.ru/cities-list.txt', encoding='utf-8') for item in data.splitlines(): args = item.split(',') cityname = args[0] cityzone = args[10][1:] # args[10] = '+4', need 4 gKursrubRuData[cityname] = cityzone return gKursrubRuData.get(city)
def getCitiesData(): afishaData = [] data = netutil.getURLResponseData(AFISHA_RU_URL, encoding='utf-8') items = re.findall(r'<a href="http://www.afisha.ru/(.+?)/changecity/">(.+?)</a>', data) for item in items: city = item[1] code = item[0] tzone = getCityTimeZone(city) afishaData.append((city, code, tzone)) print "%s [%s] UTC+%s" % (city, code, tzone) return afishaData
def getCitiesData(): afishaData = [] data = netutil.getURLResponseData(AFISHA_RU_URL, encoding='utf-8') items = re.findall( r'<a href="http://www.afisha.ru/(.+?)/changecity/">(.+?)</a>', data) for item in items: city = item[1] code = item[0] tzone = getCityTimeZone(city) afishaData.append((city, code, tzone)) print "%s [%s] UTC+%s" % (city, code, tzone) return afishaData
def getTimeZoneFromWorldTimeZonesRu(city): global gWorldTimeZonesRuData if not gWorldTimeZonesRuData: data = netutil.getURLResponseData( 'http://world-time-zones.ru/goroda.htm', encoding='windows-1251') items = re.findall(u'Часовой пояс г. (.+?)</td>.+?\(UTC\+(\d+)', data, re.DOTALL) for item in items: cityname = item[0] cityzone = item[1] gWorldTimeZonesRuData[cityname] = cityzone return gWorldTimeZonesRuData.get(city)
import re from module import io from module import netutil YANDEX_TV_URL = 'http://m.tv.yandex.ru/5' TV_PROGRAM_FILE = 'tv-yandex.txt' REPLACES = { u'СТС Золотой век': u'СТС', } EXCEPTIONS = ( u'Спорт', ) data = netutil.getURLResponseData(YANDEX_TV_URL, encoding='utf-8') if data: channels = [] entries = re.findall(r'<option value="(\d+)">(.+?)</option>', data) for entry in entries: number = int(entry[0]) # 0-7 are categories numbers if number > 7: channel = entry[1].strip() if channel not in EXCEPTIONS: channel = REPLACES.get(channel, channel) channels.append((number, channel)) out = open(TV_PROGRAM_FILE, 'wb') out.write('(\n') for ch in channels: number = ch[0]
def getTVData(): data = netutil.getURLResponseData(S_TV_URL, encoding='utf-8') if data: elements = re.findall(r'<a href="(.+?)"><img src=.+?><span>(.+?)</span></a>', data) return elements return None
# coding: utf-8 import re from module import io from module import netutil YANDEX_TV_URL = 'http://m.tv.yandex.ru/5' TV_PROGRAM_FILE = 'tv-yandex.txt' REPLACES = { u'СТС Золотой век': u'СТС', } EXCEPTIONS = (u'Спорт', ) data = netutil.getURLResponseData(YANDEX_TV_URL, encoding='utf-8') if data: channels = [] entries = re.findall(r'<option value="(\d+)">(.+?)</option>', data) for entry in entries: number = int(entry[0]) # 0-7 are categories numbers if number > 7: channel = entry[1].strip() if channel not in EXCEPTIONS: channel = REPLACES.get(channel, channel) channels.append((number, channel)) out = open(TV_PROGRAM_FILE, 'wb') out.write('(\n') for ch in channels: number = ch[0]