def UnsubscribeFromSeries(seriesname, chat_id, token, keyboard): sid = bdserials.hashf(seriesname) a.query('Delete from Podpiski where (sid = %d and uid = %d);' %(sid, chat_id)) a.save() seriesname = seriesname.encode("utf-8") text = "Вы отписались от сериала %s" %seriesname requests.get('https://api.telegram.org/bot%s/sendMessage?chat_id=%s&text=%s&reply_markup=%s' % (token, chat_id, text, keyboard))
def SubscribeToSeries(translation, series, chat_id, token, keyboard): sid = bdserials.hashf(series) a.query('Insert into Podpiski (sid, uid, translation) values (%d, %d, \'%s\')' % (sid, chat_id, translation)) a.save() series = series.encode("utf-8") translation = translation.encode("utf-8") text = ("Вы подписались на сериал %s в озвучке %s" %(series, translation)) requests.get('https://api.telegram.org/bot%s/sendMessage?chat_id=%s&text=%s&reply_markup=%s' % (token, chat_id, text, keyboard))
def UnsubscibeFromTranslation(translation, series, chat_id, token, keyboard): sid = bdserials.hashf(series) a.query('Delete from Podpiski where (sid = %d and uid = %d and translation = \'%s\')' %(sid, chat_id, translation)) a.save() series = series.encode("utf-8") translation = translation.encode("utf-8") text = "Вы отписались от сериала %s в озвучке %s" % (series, translation) requests.get('https://api.telegram.org/bot%s/sendMessage?chat_id=%s&text=%s&reply_markup=%s' % (token, chat_id, text, keyboard))
def travelState(self, message, sid, series, translation): fetch = a.fetch( "SELECT toState FROM State WHERE (message = \"%s\" and fromState = %d);" % (message, self.state)) if len(fetch) == 0: return None, None tostate = fetch[0][0] Message = self.getMessage(tostate) if self.state == tostate == 1 and len( a.fetch('Select sid from Podpiski where uid = %d' % (self.user_id))) != 0: Message = "Сериалы, на которые Вы подписаны" tostate = 2 if self.state == 4 and tostate == 1 and message == "###translationname" and len( a.fetch( 'Select pid from Podpiski where (sid = %d and uid = %d and translation = \'%s\');' % (sid, self.user_id, translation))) != 0: tostate = 5 Message = "Вы уже подписаны на сериал %s в озвучке %s" % ( series, translation) if self.state == 7 and tostate == 4 and len( a.fetch( 'Select pid from Podpiski where (sid = %d and uid = %d);' % (sid, self.user_id))) == 0: tostate = 8 Message = "Выберите озвучку" print('3', Message, tostate) a.query("UPDATE Users Set state =%d where uid = %d;" % (tostate, self.user_id)) a.save() action = a.fetch( 'Select action from State where (fromState = %d and toState = %d and message = \"%s\")' % (self.state, tostate, message)) if len(action) != 0: action = action[0][0] self.state = tostate newstate = self.state return newstate, Message, action
def updateNum(seriesname, translation, seriesnumber): # seriesnumber = a.fetch('Select num from Serials where sname = \'%s\'' %seriesname)[0][0] a.query("Update Serials set %s = %d where sname = \'%s\'" % (translation.lower().replace( ' ', ''), getDict(seriesnumber).get(translation), seriesname)) a.save()
def NewTranslation(newtranslation, series, chat_id, token, keyboard): text = "Спасибо за предложение! Мы постараемся учесть Ваше пожелание" newtranslation = newtranslation.replace('"', "'") requests.get('https://api.telegram.org/bot%s/sendMessage?chat_id=%s&text=%s&reply_markup=%s' % (token, chat_id, text, keyboard)) a.query('Insert into NewTranslations(translation, series, user) values (\"%s\", \"%s\", \"%d\")' % (newtranslation, series, chat_id)) a.save()
def notify(): # da1 = date(2017, 3, 25) da = datetime.today() da1 = datetime.date(da) da = int(datetime.toordinal(da1)) originalfeth = a.fetch( "Select Podpiski.uid, Episodes.sname, Episodes.ename, Episodes.eid from Episodes inner join Podpiski on Podpiski.sid = Episodes.sid where (Podpiski.translation = 'Original' and Episodes.date = %d);" % da) print(originalfeth) if originalfeth != None: token = '308210124:AAHkb6qVLTqo0pIKsn_IQTZqvYJ7wpzVJn0' for i in originalfeth: series = (i[1]).encode('utf-8') episode = (i[2]).encode('utf-8') translation = 'Original' eid = i[3] text = "Сегодня (%s) вы можете посмотреть серию \'%s\' сериала \'%s\' в озвучке \'%s\'" % ( da1, episode, series, translation) chat_id = i[0] requests.get( 'https://api.telegram.org/bot%s/sendMessage?chat_id=%s&text=%s' % (token, chat_id, text)) seriesnumber = a.fetch( 'Select num from Serials where sname = \'%s\'' % series) if seriesnumber != None: seriesnumber = seriesnumber[0][0] for elem in req.getDict(seriesnumber).keys(): summa = len(req.getDict(seriesnumber).keys()) a.query("UPDATE Episodes set %s = -1 where eid = %d;" % (elem.lower().replace(' ', ''), eid)) a.query( 'Update Episodes set original = 0 where eid = %d;' % eid) a.query('Update Episodes set summ = %d' % summa) a.save() comingseries = a.fetch( 'Select sname from Episodes where original = 0 group by sname') for i in comingseries: #series series = i[0].encode('utf-8') new = req.compare(series) print(new) for tr in new: #translations sid = bdserials.hashf(series) fetchepisodes = a.fetch( "Select ename, eid from Episodes where %s = -1 order by date limit %d;" % (tr[0], tr[1])) for st in fetchepisodes: a.query('Update Episodes set %s = 0 where eid = %d;' % (tr[0].lower().replace(' ', ''), st[1])) a.save() summ = a.fetch('Select summ from Episodes where eid = %d;' % st[1])[0][0] summ -= 1 if summ == 0: a.query("Delete from Episodes where eid = %d;" % st[1]) a.save() else: a.query("Update Episodes set summ = %d where eid = %d;" % (summ, st[1])) a.save() fetchusers = a.fetch( "Select uid from Podpiski where sid = %d and translation = \'%s\';" % (sid, tr[0])) for user in fetchusers: # users chat_id = user[0] episode = st[0].encode('utf-8') trans = tr[0].encode('utf-8') token = '308210124:AAHkb6qVLTqo0pIKsn_IQTZqvYJ7wpzVJn0' text = "Сегодня (%s) вы можете посмотреть серию \'%s\' сериала \'%s\' в озвучке \'%s\'" % ( da1, episode, series, trans) requests.get( 'https://api.telegram.org/bot%s/sendMessage?chat_id=%s&text=%s' % (token, chat_id, text))
def createUser(self): state = 0 a.query("INSERT INTO Users (uid, state) VALUES (%d, %d);" % (self.user_id, state)) a.save()