def validate_kronika(content): date_now = datetime.now().strftime("%Y-%m-%d %H:%M:%S") new_content = [] # Lemuria specific parsing! for item in content: new_item = {} new_item['event_date'] = lemu_datetime.process_datetime( item['event_date']).strftime("%Y-%m-%d %H:%M:%S") new_item['from_orszag_nev'] = item['from_orszag_nev'] new_item['from_orszag_id'] = item['from_orszag_id'] new_item['to_orszag_nev'] = item['to_orszag_nev'] new_item['to_orszag_id'] = item['to_orszag_id'] new_item['is_successful'] = '0' if 'megpróbálták' in item[ 'event_result'] else '1' try: item['event_result_2'] # TODO: Make it to more beautiful # NOTE: Lemuria specific parsing digit_pattern = re.compile(r'(\d+)') res = re.search(digit_pattern, item['event_result_2']) new_item['result'] = int(res.group()) except TypeError: new_item['result'] = 0 new_item['event_type'] = item['event_type'] new_item['other_datum_uploaded'] = date_now new_item['other_who_uploaded'] = user.get_username() new_content.append(new_item) return new_content
def index(): if Access_token == "": req = urllib2.Request("https://api.clarifai.com/v1/token/") data = {"client_id": CLIENT_ID, "client_secret": CLIENT_SECRET, "grant_type": "client_credentials"} req.data = urllib.urlencode(data) u = urllib2.urlopen(req) response = u.read() data = json.loads(response) global Access_token Access_token = data["access_token"] paths = user.get_pics("all") images = [] tags = [] tagStrings = [] count = 0 for i in paths: images.append([]) temp = i[0][13:] images[count].append(temp) count = count + 1 for e in images: e.append(user.get_name("static/images"+e[0])[0][0]) e.append(user.get_username(user.match_UID(e[1]))) e.append(user.get_lat("static/images"+e[0])[0][0]) e.append(user.get_lon("static/images"+e[0])[0][0]) #get tags from database for i in range(len(images)): tags.append(user.get_tags(path+images[i][0])) for tag in tags: tagStrings.append(generateTags(tag[0])) if "username" not in session: return render_template("index.html", images=images, tagStrings=tagStrings) return render_template("index.html",username=session['username'], images=images, tagStrings=tagStrings)
def validate_gomb(content): new_content = {} new_content['orszag_nev'] = content['orszag_nev'] new_content['orszag_id'] = int(content['orszag_id']) try: content['sarkanykod'] # TODO: Optional - make it beautiful if r'[SárkányKöd]' in content['sarkanykod']: new_content['sarkanykod'] = 1 # TODO: True else: new_content['sarkanykod'] = 0 # TODO: False except TypeError: # 'sarkanykod' is not subscriptable new_content['sarkanykod'] = 0 # TODO: False new_content['birodalom_nev'] = content['birodalom_nev'] new_content['birodalom_id'] = int(content['birodalom_id']) new_content['korszak'] = int(content['korszak']) new_content['sziget'] = content['sziget'] new_content['gyalogsag'] = int(content['gyalogsag']) new_content['ostromgep'] = int(content['ostromgep']) new_content['nep'] = content['nep'] new_content['vedo'] = int(content['vedo']) new_content['elit_vedo'] = int(content['elit_vedo']) new_content['rang'] = content['rang'] new_content['tamado'] = int(content['tamado']) new_content['elit_tamado'] = int(content['elit_tamado']) new_content['harci_kedv'] = int(content['harci_kedv']) new_content['hajok'] = int(content['hajok']) new_content['terulet'] = int(content['terulet']) new_content['lakos'] = int(content['lakos']) new_content['magia'] = int(content['magia']) new_content['mana'] = int(content['mana']) new_content['munkanelkuli_munkas'] = content[ 'munkanelkuli_munkas'] # Possible contains '%' new_content['munkanelkuli_bolcs'] = content[ 'munkanelkuli_bolcs'] # Possible contains '%' new_content['runa'] = int(content['runa']) new_content['hit'] = int(content['hit']) new_content['alvilag'] = int(content['alvilag']) new_content['armany'] = int(content['armany']) new_content['hangulat'] = float(content['hangulat'].replace( ',', '.')) # Important format for float handling new_content['dekadencia'] = int(content['dekadencia']) new_content['denar'] = int(content['denar']) new_content['termeny'] = int(content['termeny']) new_content['pontszam'] = int(content['pontszam']) new_content['hirnev'] = int(content['hirnev']) new_content['helyezes_1'] = int(content['helyezes_1']) new_content['helyezes_2'] = int(content['helyezes_2']) new_content['datum_created'] = content['datum_created'] new_content['other_datum_uploaded'] = datetime.now().strftime( "%Y-%m-%d %H:%M:%S") new_content['other_who_uploaded'] = user.get_username() new_content['other_comment'] = '-' # TODO return new_content
def validate_felmeres(content, datum_result): new_content = {} is_ok = True date_now = datetime.now().strftime(FORMAT_DATE_EXPECTED) new_content['orszag_nev'] = content['orszag_nev'] if new_content['orszag_nev'].strip() == '': is_ok = False err_msg = 'Felmérés: Invalid orszag_nev parsed' eventlog.log_error(err_msg) new_content = err_msg return new_content, is_ok new_content['orszag_id'] = int(content['orszag_id']) if datum_result: try: # Mode 1: normal datum datum_result = datetime.strptime(datum_result, FORMAT_DATE_EXPECTED) new_content['datum_created'] = datum_result except ValueError: # Mode 2: msg used datum format date_converted = datetime.strptime(datum_result, FORMAT_DATE_MSG_ACCEPTED) new_content['datum_created'] = date_converted.strftime( FORMAT_DATE_EXPECTED) else: new_content['datum_created'] = date_now new_content['felmeres_tipus'] = content['felmeres_tipus'].replace( 'krónikája', 'krónika') # Only for krónika felmérés extension new_content['content'] = content['content'] # Handle the "Szövetségfelmérés" content_birodalom = content['content_birodalom'] if hasattr( content, 'content_birodalom') else None if content_birodalom: new_content['content'] = content_birodalom + content['content'] print('"szovetseg felmeres"') else: print('Not "szovetseg felmeres"') new_content['other_datum_uploaded'] = date_now new_content['other_who_uploaded'] = user.get_username() new_content['other_comment'] = '-' # TODO return new_content, is_ok
def recv_captcha(self, mailfrom, msg): """ Receives and verifies captcha. """ subject = msg['Subject'] orgidentifier = string.split(subject,' ')[-1] logging.debug('Orig CAPTCHA identifier\t: %s', orgidentifier) # TODO: Reject if original identifier is not in DB try: if msg.is_multipart(): answer = msg.get_payload(0).get_payload().splitlines()[0].strip() else: answer = msg.get_payload().splitlines()[0].strip() except: return identifier = self.db.hash_data(Address(mailfrom).address, answer) match = self.db.get_captcha_word(identifier) if match != None and match['word'] == answer: # Update captcha status to CAPTCHA_APPROVED cid, rid, word = match adata = self.db.get_alias_data(rid) aobj = Alias(**adata) user = User(**self.db.get_user(uid=aobj.get_uid())) # send message to recipient's alias requesting mailfrom's permission to send msg = UserMessage('senderverify.senduserreq', \ fromaddx = self.cfg.SVCALIAS, \ aliasaddx = aobj.get_alias_address(), \ useraddx = user.get_account_address(), \ requestor = mailfrom) msg.generate_message_id(self.cfg.DOMAIN) self.db.set_captcha(msg['Message-ID'], '', cid, rid, self.db.CAPTCHA_APPROVED) logging.debug('Sending approval request to user %s', user.get_username()) self.send(msg['From'], [user.get_forwarding_address()], msg) # Delete identifier from database #self.db.delete_captcha_identifier(identifier) else: # TOFIX: should replace with new captcha and increment numtries; pass
def validate_varazslatok_felmerese(content): new_content = {} is_ok = True date_now = datetime.now().strftime("%Y-%m-%d %H:%M:%S") new_content['orszag_nev'] = content['orszag_nev'] new_content['orszag_id'] = int(content['orszag_id']) new_content['datum_created'] = date_now new_content['felmeres_tipus'] = 'Varázslatok' new_content['content'] = content['content'] new_content['other_datum_uploaded'] = date_now new_content['other_who_uploaded'] = user.get_username() new_content['other_comment'] = '-' # TODO return new_content, is_ok
def validate_piac(content, created_date): date_now = datetime.now().strftime("%Y-%m-%d %H:%M:%S") new_content = [] # Lemuria specific parsing! for item in content: new_item = {} new_item['termek'] = item['termek'] new_item['mennyiseg'] = int(item['mennyiseg']) new_item['ar'] = int(item['ar']) new_item['datum_created'] = created_date new_item['other_datum_uploaded'] = date_now new_item['other_who_uploaded'] = user.get_username() new_content.append( (new_item['termek'], new_item['mennyiseg'], new_item['ar'], new_item['datum_created'], new_item['other_datum_uploaded'], new_item['other_who_uploaded'])) return new_content
def profile(): if 'username' in session: paths = user.get_pics(user.get_UID(session['username'])) images = [] tags = [] tagStrings = [] count = 0 for i in paths: images.append([]) temp = i[0][13:] images[count].append(temp) count = count + 1 for e in images: e.append(user.get_name("static/images"+e[0])[0][0]) e.append(user.get_username(user.match_UID(e[1]))) for i in range(len(images)): tags.append(user.get_tags(path+images[i][0])) for tag in tags: tagStrings.append(generateTags(tag[0])) return render_template("profile.html",images=images,username=session['username'],tagStrings=tagStrings) return redirect(url_for("login"))
def get_deck(dId): """Get a deck in json format Retrieves the deck information and all associated cards and jsonifys them format defined by [TODO: insert the link to the formatting of the json format for deck] """ ret = {} # get the deck information g.cur.execute(""" SELECT name, creator, description, deck_id FROM decks WHERE id=%s """, dId) name, creator, desc, deck_id = g.cur.fetchone() ret['name'] = name ret['creator'] = user.get_username(creator) ret['description'] = desc ret['deck_id'] = deck_id g.cur.execute(""" SELECT sidea, sideb, card_id FROM cards WHERE deck=%s """, int(dId)) ret['cards'] = [{'index': c[2], 'sideA': c[0], 'sideB': c[1]} for c in g.cur.fetchall()] return ret
def reservate_tomorrow_p(user, roomId=6, seat_no=50, start=9, end=17): today = datetime.date.today() tomorrow = today + datetime.timedelta(days=1) if user.rtn_token() == None: user.get_token() user.reservate(roomId, seat_no, str(tomorrow), start, end) hw_rs, _, __, ___, begin, end = user.reservation() if hw_rs == True: return for i in range(5): if hw_rs == True: return msg = user.get_username() + str(hw_rs) util.Util.sendMail('*****@*****.**', 'reservate_tomorrow error' + str(i) + ':' + msg) time.sleep(1) hw_rs, _ = user.reservate(roomId, seat_no, str(tomorrow), start, end) if hw_rs == True: return hw_rs, _ = user.reservate_exclude(roomId, str(tomorrow), start, end)
def page(response): #user = User.get(username) auth.require_user(response) user = auth.get_user(response) print "name: " + str(user) if user == None: return else: context = {'title': 'Home Page', 'firstname': user.get_first_name(), 'lastname' : user.get_last_name(), 'subjects' : ['maths', 'english', 'physics', 'chemistry'], 'wallorfeed':'feedupdate', 'user':user, 'current_Wall':user.get_username(), 'can_use_wall':'True' } template.render_template("templates/home.html", context, response)
from screen import ScreenRes var_ = GetParams("var_") try: SetVar(var_, ScreenRes.get()) except Exception as e: print("\x1B[" + "31;40mAn error occurred\u2193\x1B[" + "0m") PrintException() raise e if module == "getUserName": import user try: username = user.get_username() var_ = GetParams("var_") SetVar(var_, username) except Exception as e: print("\x1B[" + "31;40mAn error occurred\u2193\x1B[" + "0m") PrintException() raise e if module == "lockWindows": from screen import ScreenRes try: print("Se ha bloqueado su pantalla!") ScreenRes.lock_windows() except Exception as e: print("\x1B[" + "31;40mAn error occurred\u2193\x1B[" + "0m")
def forward(self, mailfrom, rcpttos, msg): """ Handles Case 2, where email is not from a service user and so needs to be forwarded to various aliases. """ for rcpt in rcpttos: prcpt = Address(rcpt) alias_pair = prcpt.parse_alias_address() logging.debug(rcpt) if not alias_pair: # if the domain is SERVERNAME, sender screwed up; return error to sender... if prcpt.is_servername(): logging.info('Encountered improperly formatted ' 'address "%s" in recipients field', prcpt.address) # Create error response message err = ErrorMessage('forward.badformat', fromaddx = self.cfg.SVCALIAS, toaddx = mailfrom, badalias = prcpt.address) self.send(err['From'], [mailfrom], err) # ... otherwise ignore; not our job to send to non-users logging.info('Encountered recipient outside our domain; ignoring') else: alias_data = self.db.get_alias_data(*alias_pair) if alias_data: fwd_alias = Alias(**alias_data) userdata = self.db.get_user(uid=fwd_alias.get_uid()) assert userdata is not None user = User(**userdata) logging.debug('is trusted? %s', fwd_alias.is_trusted()) # handle trustedness here; if not fwd_alias.is_trusted(): mfrom = Address(mailfrom) # if sender is in trusted group, then it's all right; if self.db.is_trusted_correspondent(mfrom, \ user.get_salt(), \ fwd_alias.get_rid(), \ fwd_alias.get_trusted_timestamp()): pass # TODO: send/append something about newer alias to send to? else: capstat = self.db.get_capstat(mfrom, \ user.get_salt(), \ fwd_alias.get_rid()) logging.debug('capstat=%s', capstat) if capstat < self.db.CAPTCHA_PENDING: logging.debug('captcha not yet sent; trying to send one') # If not approved, send captcha to sender and drop mail. # TODO: Perhaps we can cache the mail somewhere. cid = self.db.get_cid(mfrom, user.get_salt()) self.send_captcha(mailfrom, cid, fwd_alias) #self.db.set_capstat(cid, # fwd_alias.get_rid(), # self.db.CAPTCHA_PENDING) logging.debug('done sending captcha') elif capstat == self.db.CAPTCHA_PENDING: logging.debug('captcha was already sent; still waiting for solution') elif capstat == self.db.CAPTCHA_APPROVED: logging.debug('captcha approved, but not yet user approved') # if user denied, # TODO: just ignore? or do something more? # pass # if user judgement pending, send message # informing them they must wait for user's approval? if capstat == self.db.USER_PENDING: pass # TODO: send message return # TODO: can consult a whitelist/blacklist/etc. here fwd_addx = Address(user.get_forwarding_address()) fwd_addx.realname = prcpt.realname logging.info('Found alias for account (%s) Forwarding message to %s', \ user.get_username(), fwd_addx.address) # Add hint as recipient name. The hint/domain is used as a reminder # to the user where this email address was originally created for. # But since we did not update Reply-To, it will drop off when the # user replies to the message. rcptaddr = Address(rcpt) if rcptaddr.get_realname() == '': if fwd_alias.get_hint() != None: rcptaddr.set_realname(fwd_alias.get_hint()) elif fwd_alias.get_domain() != None: rcptaddr.set_realname(fwd_alias.get_domain()) msg.replace_address('To', rcpt, rcptaddr) acct_addx = Address(user.get_account_address()) acct_addx.realname = prcpt.realname #del msg['message-id'] #del msg['DKIM-Signature'] if 'To' in msg: msg.replace_header('To', msg['To'] + ', ' + str(acct_addx)) if 'Reply-To' in msg: msg.replace_header('Reply-To', msg['reply-to'] + ', ' + rcpt); else: msg.add_header('Reply-To', mailfrom + ', ' + rcpt); if 'Message-ID' not in msg: msg.generate_message_id(self.cfg.DOMAIN) self.send(mailfrom, [str(fwd_addx)], msg) self.db.add_history(fwd_alias.get_rid(), False, [Address(mailfrom)], msg['Message-ID'], user.get_salt()) else: logging.info("Couldn't find data for alias (%s,%d)", *alias_pair) return
def validate_pontlista(content): new_content = {} new_content['orszag_nev'] = content['orszag_nev'] new_content['orszag_id'] = int(content['orszag_id']) new_content['helyezes'] = int(content['helyezes']) new_content['szabi'] = 0 new_content['ved'] = 0 new_content['tilt'] = 0 # Lemuria specific parsing! if content['status'] == 'Szabi': new_content['szabi'] = 1 elif content['status'] == 'VED': new_content['ved'] = 1 elif content['status'] == 'Tilt': new_content['tilt'] = 1 else: # Not Szabi, not VED, not Tilt pass try: content['sarkanykod'] # TODO: Make it more beautiful # NOTE: Lemuria specific parsing if r'[SK]' in content['sarkanykod']: new_content['sarkanykod'] = 1 # TODO: True else: new_content['sarkanykod'] = 0 # TODO: False except TypeError: # 'sarkanykod' is not subscriptable new_content['sarkanykod'] = 0 # TODO: False # TODO: Support new_content['sziget'] = None new_content['hirnev'] = int(content['hirnev']) new_content['pontszam'] = int(content['pontszam']) try: content['tavolsag'] # TODO: Make it more beautiful # Check it is exists (e.g. at TOP50 list it is not existing) new_content['tav'] = float(content['tavolsag']) except TypeError: new_content['tav'] = None # TODO: Future improvement: datum_created != other_datum_uploaded datetime_now = datetime.now().strftime("%Y-%m-%d %H:%M:%S") new_content['datum_created'] = datetime_now # TODO: Support new_content['magved'] = None new_content['other_datum_uploaded'] = datetime_now new_content['other_who_uploaded'] = user.get_username() new_content['other_comment'] = '-' # TODO # TODO: Support new_content['pontlista_type'] = None new_content['torolt'] = 0 # False return new_content