-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplpackagetrack.py
executable file
·40 lines (29 loc) · 1.23 KB
/
plpackagetrack.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
#!/usr/bin/env python
import sys
from providers import *
class tracking(object):
def __init__(self):
self._providers = {}
for module in sys.modules.keys():
if module.startswith('providers.'):
self._providers[module[10:]] = globals()[module[10:]]
def providers(self):
return (list(self._providers.keys()))
def track(self, provider, number):
return (getattr(self._providers[provider], 'track')(number))
def long_name(self, provider):
return (getattr(self._providers[provider], 'NAME'))
def guess(self, number):
order = {}
for provider in self._providers.keys():
if getattr(self._providers[provider], 'guess')(number):
order[provider] = 10 * getattr(self._providers[provider], 'POPULARITY')
else:
order[provider] = getattr(self._providers[provider], 'POPULARITY')
return sorted(order, key=order.get)[::-1]
def track_all(self, number):
for provider in self.guess(number):
tracked = getattr(self._providers[provider], 'track')(number)
if tracked.status() != 'NOTFOUND':
return (tracked)
return None