forked from trolldbois/canalplus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
74 lines (53 loc) · 1.75 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2011 Loic Jaquemet loic.jaquemet+python@gmail.com
#
import codecs,logging,os,random
from main import Main
from parser import ThemeParser,CategorieParser,EmissionParser,VideoParser,StreamParser
import lxml,lxml.html
from model import Theme,Categorie,Emission,Video,Stream
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session,sessionmaker
log=logging.getLogger('test')
engine = create_engine('sqlite:///canalplus.db',echo=True)
Session = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=engine))
def showTree():
logging.basicConfig(filename='show.log',level=logging.DEBUG)
main=Main()
main.parseContent()
printTree(main.themes)
def printTree(themes):
for t in themes:
print t.text
for c in t.categories:
print '\t',c.text
for e in c.emissions:
print '\t\t',e.text
for v in e.videos:
print '\t\t\t',v.text, '%d videos'%( len(v.streams) )
def testTheme(filename='test/index.html'):
#logging.basicConfig(filename='log.debug',level=logging.DEBUG)
logging.basicConfig(level=logging.DEBUG)
main=Main()
filefetcher=FileFetcher(filename)
main.parseContent(filefetcher)
print main.themes
if True:
printTree(main.themes)
return
def testVideoParser(filename=None):
logging.basicConfig(level=logging.DEBUG)
f=file('test/guignols.html')
emission=Emission(pid=1784,text='LES GUIGNOLS')
root=lxml.html.parse(f)
videoParser=VideoParser(emission)
videos=[videoParser.parse(element) for element in root.xpath(videoParser.xPath)]
print videos
#testVideoXml()
testVideoParser()
#testGuignols()
#testTheme()