Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ========================== CAŁA KLASA ======================================================
- class Wykop:
- lastcheck = 0
- normaldelay = 100
- activedelay = 20
- cache = None
- api = None
- def __init__(self):
- self.api = _wykop.WykopAPI("AlSmtKUGQu", "TcR5hevkSV")
- self._auth()
- thread.start_new_thread(self.update,())
- def update(self):
- while True:
- sleep(1)
- if self.getNextRefresh() <= 0:
- self.refresh()
- def getNextRefresh(self):
- delaj = self.normaldelay
- if self.cache != None and len(self.cache) > 0:
- delaj = self.activedelay
- return round(delaj-(time()-self.lastcheck),0)
- def setDelay(self, normal, active):
- self.normaldelay = normal
- self.activedelay = active
- def _auth(self):
- self.api.authenticate("skew","6QauQGs4yC76dU4gS1U5")
- def refresh(self):
- try:
- print "Refreshing wykop"
- self.lastcheck = time()
- wykopresult = self.api.request("mywykop","notifications")
- self.cache = []
- for key in wykopresult:
- if key.new == True:
- if key.type == "register":
- self.cache.append(key.author+"\nutworzyl konto")
- elif key.type == "observe":
- self.cache.append(key.author+"\nobserwuje cie")
- elif key.type == "unobserve":
- self.cache.append(key.author+"\nnie obserwuje")
- elif key.type == "entry_comment_directed":
- self.cache.append(key.author+"\ndodal komentarz")
- elif key.type == "entry_directed":
- self.cache.append(key.author+"\nwola cie!")
- elif key.type == "entry_tag":
- self.cache.append(key.author+"\nnapisal wpis")
- elif key.type == "link_comment_directed":
- self.cache.append(key.author+"\nwola cie!")
- elif key.type == "link_promoted":
- self.cache.append("Twoj link jest\nna glownej!")
- elif key.type == "link_directed":
- self.cache.append(key.author+"\ndodal link dla")
- elif key.type == "system":
- self.cache.append("Nowy komunikat\nsystemowy!")
- elif key.type == "badge":
- self.cache.append("Masz nowe\nodznaczenie")
- elif key.type == "support_answer":
- self.cache.append("Nowa odpowiedz\n pomocy!")
- elif key.type == "pm":
- self.cache.append(key.author+" napisal ci PW")
- print "Wykop refresh complete"
- except:
- self._auth()
- def get(self, ref=False):
- if ref == True or self.cache == None:
- self.refresh()
- return self.cache
- ============================================== UŻYCIE ==========================================================================
- wykop = Wykop()
- while True:
- wykopdata = wykop.get()
- if len(wykopdata) > 0:
- lcd.clear()
- lcd.writeMsg(wykopdata[0],0.1)
- sleep(10)
- # Co by CPU nie zabić
- time.sleep(0.01)
Advertisement
Add Comment
Please, Sign In to add comment