leggi.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import json
  2. import sys
  3. from itertools import imap
  4. from splinter import Browser
  5. from dirset import DirSet
  6. def read_pass_file(fname):
  7. with open(fname) as buf:
  8. user = buf.readline().strip()
  9. pwd = buf.readline().strip()
  10. return user, pwd
  11. def get_calls(user, password):
  12. with Browser('phantomjs') as b:
  13. b.visit('https://www.messagenet.com/')
  14. b.fill('userid', user)
  15. b.fill('password', password)
  16. b.find_by_css('#login button').click()
  17. b.visit('https://www.messagenet.com/voip/log/?chiamate=ricevute')
  18. rows = b.find_by_css('.log .statusKO')
  19. for r in rows:
  20. cells = r.find_by_tag('td')[1:3]
  21. yield tuple(imap(lambda c: c.value, cells))
  22. def save_calls(calls, datadir):
  23. s = DirSet(datadir)
  24. for call in imap(lambda t: '\t'.join(t), calls):
  25. if s.add(call): # wasn't existing before
  26. print 'NEW: %s' % call
  27. if __name__ == '__main__':
  28. conf = json.load(open('defaultconf.json'))
  29. if len(sys.argv) == 2:
  30. conf.update(json.load(open(sys.argv[1])))
  31. user, password = read_pass_file(conf['credfile'])
  32. calls = tuple(get_calls(user, password))
  33. save_calls(calls, conf['datadir'])