Tuesday, December 6, 2011

Телевизийн мэдээ хусдаг скрипт хөөрхөн шөл ашиглаж хийв.

# -*- coding: UTF8 -*-
from datetime import datetime, timedelta
from urllib import urlopen
from BeautifulSoup import BeautifulSoup

channel_list = [
(85,'MN25 телевиз'),
(138,'Eagle Телевиз'),
(90,'ТМ телевиз'),
(91,'C1 телевиз'),
(92,'SBN телевиз'),
(93,'NTV '),
(95,'Боловсрол Суваг'),
(99,'Эх Орон Телевиз'),
(111,'МОНГОЛ ТВ'),
(113,'Айст Телевиз'),
(131,'Star TV'),
(132,'Шинэ Дэлхий'),
(136,'Za ТV'),

def get_channel_name(cid):
    cid = int(cid)
    for code,val in channel_list:
        if code==cid:
            return val

def find(soup):
    days = set([])
    for div in soup.findAll('div'):
        if div and div.has_key('class'):
            if div['class']=='tdiv' and div.has_key('onclick'):
                ch_id = a[-1]
                ch_time = datetime.fromtimestamp(int(a[-3]))-timedelta(hours=15)
                pr_name = ''.join(a[:-3])
                channel = get_channel_name(ch_id)
                print channel, pr_name, ch_time.strftime('%H:%M'), ch_time.isoweekday()

if __name__=='__main__':
    for cid, val in channel_list:
        html = urlopen('http://zuragt.mn/?channel={0}'.format(cid)).read()
        soup = BeautifulSoup(html)