def sending(request): data = json.loads(request.body) try: email = int(data['email']) except: response = {'status': 0, 'txt': "Email template not selected!"} return HttpResponse(json.dumps(response), content_type='application/json') try: attachments = int(data['attachments']) except: response = {'status': 0, 'txt': "Attachment template not selected!"} return HttpResponse(json.dumps(response), content_type='application/json') try: users = [int(x) for x in data['users']] if len(users) == 0: raise Exception() except: response = {'status': 0, 'txt': "There is no user!"} return HttpResponse(json.dumps(response), content_type='application/json') ebay_users = EbayUser.objects.filter(pk__in=users) attachment = AttachmentTemplate.objects.filter(pk=attachments) email = EmailTemplate.objects.filter(pk=email) response = {'status': 1, 'txt': 'nice!'} for ebay_user in ebay_users: ebay_user.sent = True ebay_user.date_sent = time.now() ebay_user.save() return HttpResponse(json.dumps(response), content_type='application/json')
def KollSendDataSQL (w,SensorID,date): # Open database connection #db = mysql.connector.connect(host='megatrenddb.ctcmpabozwdk.us-west-2.rds.amazonaws.com' try: cnx = mysql.connector.connect(host='megatrenddb.ctcmpabozwdk.us-west-2.rds.amazonaws.com' ,user='******' ,password='******' ,database='' ) # prepare a cursor object using cursor() method cursor = cnx.cursor() #DATETIME values in 'YYYY-MM-DD HH:MM:SS' format add_reading = ("INSERT INTO `mess_all`.`koll_all` " "(`w`, `SensorID`, `datetime`) " "VALUES (%s, %s, %s)") data_readings = (w,SensorID,date) cursor.execute(add_reading, data_readings) # execute SQL query using execute() method. # Make sure data is committed to the database cnx.commit() cursor.close() cnx.close() except mysql.connector.Error as err: print("Something went wrong: {}".format(err)) patch = "/home/ec2-user/" filename = "sqllogkoll.txt" logfile = open(patch+filename,'a+') logfile.write ('%s;%s' % (err,time.now()))
def premor(odmor): odmor.append(datetime.now()) zaccas = time.now() trenutno = 0 while trenutno < 1800: trenutno = datetime.now()-zaccas return 0
def umfrage_jahandler(self, bot, update): if self.umfrage_starter is None or update.message.from_user == self.umfrage_starter or update.message.from_user in self.umfrage_approvers: return self.umfrage_approvers.append(update.message.from_user) approvers_limit = { 'Heißgetränk': 3, 'Galerie': 1, 'Eis': 3, 'Karte aufladen': 1 } if len(self.umfrage_approvers) >= approvers_limit[self.umfrage_name]: timestr = (time.now() + timedelta(minutes=5)).strftime("%H:%M") abfahrt = {'Treffen um 12h15 im Mensafoyer.'} log.info('Poll successful') approvers = self.umfrage_approvers participants = ', '.join( [a.first_name for a in ha]) + f' und {self.umfrage_starter.first_name}' self.broadcast( f'{self.umfrage_name}! {emoji[self.umfrage_name]}\nMit {participants}. {abfahrt[self.umfrage_name]}', bot, tastatur=telegram.ReplyKeyboardRemove()) self.umfrage_starter = None self.umfrage_approvers = []
def do(self): # do your thing here session_list = Session.objects.all() current_time = time.now() for session in session_list: if session.start_time == current_time: session.isLocked = True if session.end_time == current_time: session.tutor.tutor.wallet += session.tutor.hourlyRate session.save()
def __init__(self, basepath = None): if not basepath: self.basepath = os.getcwd() else: self.basepath = basepath self.config = {'template_dir' : opj(basepath, 'templates'), 'data_dir' : opj(basepath, 'data'), 'src_dir' : opj(basepath, 'src'), 'dest_dir' : opj(basepath, 'output'), 'files_dir' : opj(basepath, 'files'), 'name' : '', 'template' : 'default.html', 'time' : time.now()} fh = open(opj(self.basepath, 'config.yaml'), 'r') self.config.update(yaml.load(fh.read())) settings_dir = opj(basepath, 'settings') if os.path.isdir(opj(basepath, 'settings')): # import settings.py which should contain a routing table # at the minimum?? self.settings = imp.load_source('settings', opj(settings_dir, 'settings.py')) else: self.settings = { 'routes' : [('.*.html$', HTMLPage)] } self.things = [] self.pages = [] self.files = [] self.routes = self.settings['routes'] for i, rt in self.routes.enumerate(): self.routes[i] = (re.compile(rt[0]), rt[1]) for path, ds, fs in os.walk(self.config['src_dir']): for f in fs: relpath = opj(path, f) fullpath = opj(self.config['src_dir'], path, f) fname, ext = os.path.splitext(f) for pattern, handler in self.routes: m = pattern.match(relpath) if m: self.things.append(handler(self, relpath)) print handler break fdir = self.config['files_dir'] for path, ds, fs in os.walk(fdir): for f in fs: src = opj(fdir, path, f) dest = opj(self.config['dest_dir'], path, f) src_time = os.path.getmtime(src) dest_time = os.path.getmtime(dest) if src_time > dest_time: print "Copying {0} --> {1}".format(src, dest) else: print "The files are fine"
def update_user(request): allowed_fields = [x.attname for x in EbayUser._meta.fields] data = request.POST data = {k: v for k, v in data.items() if k in allowed_fields} user, created = EbayUser.objects.get_or_create(email=data['email']) for k, v in data.items(): setattr(user, k, v) user.cleaned = True user.cleaned_date = time.now() user.save() return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
def validator(self, postData): errors = {} if len(postData['task']) < 1: errors['task'] = "Enter a tasks." if len(postData['status'])<1: errors['status']="Enter a status" if len(postData['date']) < 1: errors['date'] = "Enter a Data." elif postData['date'] < str(date.now()): errors['date'] = "Date must be in the future." if len(postData['time']) < 1: errors['time'] = "Enter a Time." elif postData['time'] < str(time.now()): errors['time'] = "time must be in the future." return errors
def auth_session_logout(user_account_number): now = time.now() print("Time of logout: ", now) logout_successful = False if os.path.exists(user_db_path + str(user_account_number) + ".txt"): try: os.remove(user_db_path + str(user_account_number) + ".txt") logout_successful = True except FileNotFoundError: print("Unable to logout") finally: return logout_successful
def _value_default(self): return time.now()
from datetime import time from datetime import datetime print "Today is {0}".format(str(datetime.today())) print "Time is {0}".format(str(time.now()))
from datetime import time n = time.now() print(n.strftime("%H:%M:%S"))