-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanzeigen.py
executable file
·68 lines (58 loc) · 1.91 KB
/
anzeigen.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# tested with python 3.3.2
import sys
if sys.version_info < (3, 3):
raise "must use python 3.3 or greater"
import os,logging,traceback
from DDSession import DDSession
from Anzeige import Anzeige
# logging initializing
import http.client as http_client
http_client.HTTPConnection.debuglevel = 0
logging.basicConfig()
logging.getLogger().setLevel(logging.INFO)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.INFO)
requests_log.propagate = False
log = logging.getLogger(__name__)
ignoreFileList=['.DS_Store']
# login to daildose
session=DDSession()
session.login()
# delete all ads
session.anzeigenLoeschen()
# add all adds
exceptions=[]
dirs = sorted(os.listdir(session.config['anzeigenpath']))
for dir in dirs:
absolutepathdir=os.path.join(session.config['anzeigenpath'],dir)
# only directories here please
if not os.path.isdir(absolutepathdir):
if dir not in ignoreFileList:
log.warn("Datei "+absolutepathdir+" wird ignoriert.")
continue
try:
# load advertisement
anzeige = Anzeige(absolutepathdir)
# upload advertisement in daildose
session.anzeigeEinstellen(anzeige)
except Exception as e:
exc_type, exc_value, exc_traceback = sys.exc_info()
log.error('Fehler beim Einstellen der Anzeige '+anzeige['title'])
exeption_hash = {'title':anzeige['title'],
'exception':e,
'exc_type':exc_type,
'exc_value':exc_value,
'exc_traceback':exc_traceback}
# collect all errors and go on
exceptions.append(exeption_hash)
# print all errors in detail
if len(exceptions)>0:
for e in exceptions:
print()
print('Error in '+e['title'])
print('=================================')
traceback.print_exception(e['exc_type'], e['exc_value'], e['exc_traceback'],limit=5, file=sys.stderr)
sys.exit(1)
sys.exit(0)