forked from leonidkozhukh/LigerTail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
defaultitemlist.py
49 lines (38 loc) · 1.32 KB
/
defaultitemlist.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
import model
import logging
import time
import random
from itemlist import itemList
from activitymanager import Singleton
class DefaultItemList(Singleton):
def __init__(self):
self.config = None
self.lastLoad = time.time()
self.secToRefresh = 120
def lazyLoad(self):
now = time.time()
refresh = False
if now - self.lastLoad > self.secToRefresh:
refresh = True
if not self.config or refresh:
self.lastLoad = time.time()
self.config = model.getDefaultLinksConfig()
self.secToRefresh = self.config.refresh_period_sec
if self.secToRefresh < 10:
self.secToRefresh = 10
logging.info('Reloading defaultlinks')
def getOrderedItems(self):
self.lazyLoad()
if self.config.enable and len(self.config.default_links_url) and not self.disallowOutgoing():
return itemList.getDefaultOrderedItems(self.config.default_links_url);
return []
def getPublisherUrl(self):
self.lazyLoad()
return self.config.default_links_url
def disallowIncoming(self):
self.lazyLoad()
return not self.config.throttle_outgoing and self.config.throttle < random.randint(0, 100)
def disallowOutgoing(self):
self.lazyLoad()
return self.config.throttle_outgoing and self.config.throttle < random.randint(0, 100)
defaultItemList = DefaultItemList()