class Notes(App): APP_ID = APP.NOTES def __init__(self): self.cache = Cache(600) super().__init__(cache=self.cache) @staticmethod def save(content): NoteModel.save_note(content) @staticmethod def load(offset): note = NoteModel.load_notes(offset) return note def execute(self, command, **kwargs): if command == 'save': self.cache.invalidate() content = kwargs['content'] self.save(content) return {} elif command == 'load': offset = kwargs.get('offset') return {'note': self.load(offset)}
class CacheEntry(Resource): def __init__(self): self.cache = Cache() def get(self, item_id): item = self.cache.get(item_id) return item, HTTPStatus.OK def delete(self, item_id): if self.cache.delete(item_id): return f'Deleted cache entry with ETag: {item_id}', HTTPStatus.ACCEPTED else: return 'Not Found', HTTPStatus.NOT_FOUND
def __init__(self): cache = Cache(60) super().__init__(app_type=APPTYPE.STREAMING, cache=cache) auth = tweepy.AppAuthHandler(self.configuration['TWITTER_APP_KEY'], self.configuration['TWITTER_APP_SECRET']) self.api = tweepy.API(auth) self.users = self.configuration['TWITTER_USERS_TO_FETCH_SCHEDULE'] rule = Rule('Schedule Finder', alarmable=False) rule.description = 'Try to find a set of schedules' rule.app_id = self.APP_ID interval = Interval(hour=1, minute=0) for user in self.users: rule.create_subrule(subrule_name=user + ':sch', func=self.get_schedule, args=user, triggers={ 'day_of_week': 'mon,tue,wed,thu,fri,sat,sun', 'hour': str(interval.hour), 'minute': str(interval.minute) }) interval.increment_15_mins() self.overseer.add_rule(rule) self.start()
def __init__(self): super().__init__() self.initUI() # self.hide() self.tweets = [] self.cache = Cache() self.fetch_tweets() self.show()
def __init__(self): cache = Cache(LocalConfigModel.retrieve('TOPTEN_CACHE_DURATION_SECS')) super().__init__(cache=cache) self.USER_AGENT = self.configuration['USER_AGENT'] self.BBN_URL = self.configuration['BBN_URL'] self.HEADERS = { 'User-Agent': self.USER_AGENT, 'Referer': self.BBN_URL, 'Origin': self.BBN_URL, 'Host': self.BBN_URL.split('//')[-1] }
def __init__(self): cache = Cache(60) super().__init__(cache=cache)
class MainWindow(QWidget): def __init__(self): super().__init__() self.initUI() # self.hide() self.tweets = [] self.cache = Cache() self.fetch_tweets() self.show() def fetch_tweets(self): self.load_tweets() def load_tweets(self): if len(self.tweets) == 0: try: f = open(lt, 'r') id = int(f.read()) print(id) f.close() except Exception as e: print(e) id = 0 else: id = self.tweets[-1].tid r = requests.get("http://127.0.0.2:8080/status/from_id/" + str(id)) if r.status_code == 200: tw = pickle.loads(r.content) tw.sort() for i in tw: for _, j in i.ent['pic']: self.cache.queue_ressource(j) for j in i.ent['profile']: self.cache.queue_ressource(j) self.cache.fetch_queue() for i in tw: self.addTweet(i) def initUI(self): self.setWindowTitle('Twitter Client') self.setWindowIcon(QIcon("twitter.svg")) QIcon.setThemeName("Adwaita") lay = QVBoxLayout(self) scr = QScrollArea(self) scr.setWidgetResizable(True) scr.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) lay2 = QVBoxLayout() self.setLayout(lay) placehold = QWidget() lay.addWidget(scr) scr.setWidget(placehold) placehold.setLayout(lay2) self.lay = lay2 lay2.setSpacing(0) lay.setSpacing(0) lay.setContentsMargins(0, 0, 0, 0) but = QPushButton("Refresh") lay.addWidget(but) but.pressed.connect(self.fetch_tweets) self.show() def addTweet(self, tweet): widget = StatusWidget(tweet, self.cache) self.tweets.append(widget) widget.delete_tweets.connect(self.deleteTweets) self.lay.addWidget(widget) def deleteTweets(self, string_id): id = int(string_id) for i in self.tweets: if i.tid <= id: self.lay.removeWidget(i) i.hide() f = open(lt, 'w') f.write(string_id) f.close()
def __init__(self): cache = Cache(5) super().__init__(cache=cache) self.PLATFORM = os.name
def __init__(self): cache = Cache(LocalConfigModel.retrieve('TOPTEN_CACHE_DURATION_SECS')) super().__init__(cache=cache)
def init_structs(cache_dir): app._db = Cache(cache_dir) app._tutors = ListOf(Tutor, app._db)
def __init__(self): self.cache = Cache(600) super().__init__(cache=self.cache)
from common.logging import LoggerHandler from common.utils import find_config_file, load_config_from_pyfile from common.cache import Cache import asyncio from .extend_drivers import extendDriver __all__ = ['log', 'config', 'cache_call', 'loop', 'extendDriver'] config_file = find_config_file() config = load_config_from_pyfile(config_file) cache_call = Cache() loop = asyncio.get_event_loop() log = LoggerHandler(file_path=config['log_file'], log_level=config['log_level']).log_init() log.info('use config file: "{}"'.format(config_file))
def __init__(self): cache = Cache(30, exclusion=('dismiss', 'force-fetch-feed')) super().__init__(app_type=APPTYPE.STREAMING, cache=cache) self.create_rss_feeds() self.create_subreddit_feeds() self.start()
def __init__(self): self.cache = Cache()