def checkqz1(): r = 0 if (request.method == "POST"): a1 = request.form['1'] a2 = request.form['2'] a3 = request.form['3'] a4 = request.form['4'] a5 = request.form['5'] if a1 == '1': r = r+1 if a2 == '1': r = r+1 if a3 == '2': r = r+1 if a4 == '2': r = r+1 if a5 == '3': r = r+1 qz1up(User_Data,r) data = getpath(4) temp = list(data) f = open(temp[1],"r") s = f.read() import json book = json.loads(s) return render_template('pg4.html',username = User_Data[1],p = book)
def get_areas(city): path = str( "http://api.geonames.org/postalCodeSearchJSON?placename={}&username=padam&maxrows=100" .format(str(city))) data = json.loads(requests.get(path).text)['postalCodes'] area_in_city = [x['placeName'] for x in data] return area_in_city
def verifylogin(): global User_Data if request.method == 'POST': email = request.form['email'] password = request.form['password'] flag,data = verify_user(email,password) if flag==0: return render_template('login.html',msg = "Incorrect email or password") #print("invalid user") else: User_Data = list(data) data = getpath(1) temp = list(data) f = open(temp[1],"r") s = f.read() import json book = json.loads(s) global q #q=[] for j in range(1,11): x = "pg" + str(j) + ".html" #x = "".join(["pg",str(i),".html"]) q.append(x) return render_template('pg1.html',username = User_Data[1],p = book)
def wat(): data = getpath(i) temp = list(data) f = open(temp[1],"r") s = f.read() import json book = json.loads(s) return render_template(q[i-1],username = User_Data[1],p = book)
def main10p(): data = getpath(9) temp = list(data) f = open(temp[1],"r") s = f.read() import json book = json.loads(s) return render_template('pg9.html',username = User_Data[1],p = book)
def beginc(): erase(User_Data) data = getpath(1) temp = list(data) f = open(temp[1],"r") s = f.read() import json book = json.loads(s) return render_template('pg1.html',username = User_Data[1],p = book)
def main9(): nextfunction(User_Data,9) data = getpath(10) temp = list(data) f = open(temp[1],"r") s = f.read() import json book = json.loads(s) return render_template('pg10.html',username = User_Data[1],p = book)
def get_task(task_id): db_task = mongo.db.tododb data = [] for tasks in db_task.find(): id = json.loads(dumps(tasks['_id'])) if task_id in id['$oid']: task = db_task.find_one({"_id": ObjectId(task_id)}) id = json.loads(dumps(task['_id'])) data.append( { "_id": id["$oid"], "title": task["title"], "description": task["description"], "done": task["done"] } ) return jsonify({'tasks':data}), 200 return jsonify({"Error ": "task is not in list"}), 404
def whatsapp(id): # Takes in Job ID and sends contacts job = Job.query.filter_by(id=int(id)).first() template = job.template[0] path = job.template[0].path message = job.template[0].message job.status = "running" db.session.commit() clubs = job.club meta = json.loads(job.meta) contacts = [] contact_schema = ClubContactSchema() # Needs a meta for cooloff period and which contact to start back from. for item in clubs: club = Club.query.filter_by(id = int(item.id)).first() data = contact_schema.dump(club)['total_contact'] for inner in data: contacts.append(inner) driver = driver_init() if 'last' in meta.keys(): start_range = int(meta['last']) else: start_range = int(0) end_range = start_range + 100 for contact in contacts[start_range:end_range]: try: num = contact['contact_one'] # Replace Message with Name num = num.replace('+' ,'') num = num.replace('-' ,'') num = num.replace(' ', '') name = contact['name'].split('-')[0] if message.find('{name}') is not - 1: formated_message = message.replace('{name}', name) else: formated_message = message whatsapp_send(driver , num , meta['timer'] , path , formated_message) except Exception as e: pass job.status = "done" meta['last'] = end_range job.meta = json.dumps(meta) driver.close() db.session.commit()
def messages(id): # Takes in Job ID and sends contacts job = Job.query.filter_by(id=int(id)).first() template = job.template[0] message = job.template[0].message job.status = "running" db.session.commit() clubs = job.club meta = json.loads(job.meta) contacts = [] contact_schema = ClubContactSchema() driver = driver_init() # Needs a meta for cooloff period and which contact to start back from. for item in clubs: club = Club.query.filter_by(id = int(item.id)).first() data = contact_schema.dump(club)['total_contact'] for inner in data: contacts.append(inner) # Nuber needs 0 before +91 for local indian numbers print(contacts) print(clubs) for contact in contacts: print(contact) try: num = contact['contact_one'] # Replace Message with Name num = num.replace('+' ,'') num = num.replace('-' ,'') num = num.replace(' ', '') num = num[2:12] name = contact['name'].split('-')[0] if message.find('{name}') is not - 1: formated_message = message.replace('{name}', name) else: formated_message = message message_send(driver , num , formated_message) except Exception as e: print(str(e)) pass job.status = "done" driver.close() db.session.commit()
def run_job(): payload = request.json print(payload) job = Job.query.filter_by(id=int(payload['curr_id'])).first() meta = json.loads(job.meta) meta['timer'] = payload['timer'] job.meta = json.dumps(meta) db.session.commit() try: task = tasks.whatsapp(job.id) print("heheheheheheheeh" + task.args) job.status = "running" db.session.commit() return jsonify({'success': 'Job started'}) except Exception as e: return jsonify({'message': 'Unable to run job. Check logs'})
def add_template(): payload = json.loads(request.form['data']) file = request.files if payload: try: new_data = Template(payload['name'], payload['message'], payload['filetype']) if len(file) != 0: file = request.files['image'] try: if file: filename = file.filename foldertemp = os.path.join(UPLOAD_FOLDER, 'templates') if os.path.exists(foldertemp): filetemp = os.path.join(foldertemp, filename) file.save(filetemp) setattr(new_data, 'path', filetemp) else: os.makedirs(foldertemp) filetemp = os.path.join(foldertemp, filename) file.save(filetemp) setattr(new_data, 'path', filetemp) else: return jsonify( {'message': 'Image file not supported.'}) except IntegrityError as e: print(str(e)) return jsonify({'message': 'Image file not supported.'}) except Exception as e: print(str(e)) db.session.add(new_data) db.session.commit() return jsonify({'success': "Data added"}) except Exception as e: # return Exception for duplicate data print(str(e)) return jsonify({'message': "Something went wrong"})
def get_all_tasks(): data = [] db_task = mongo.db.tododb if db_task.count_documents({}) > 0: for task in db_task.find().sort('sorted',pymongo.DESCENDING): id = json.loads(dumps(task['_id'])) data.append( { "id": id["$oid"], "title": task["title"], "description": task["description"], "done": bool(task["done"]) } ) return jsonify({'tasks':data}),200 else: return jsonify({'TodoList':'Todo list is empty'}), 204
def scrape_google(id): scraper = Scrape.query.filter_by(id=int(id)).first() tags = scraper.tag city = scraper.city[0].name scraper.status = "running" db.session.commit() city_obj = City.query.filter_by(id=int(scraper.city[0].id)).first() meta = json.loads(scraper.meta) areas = get_areas(city) for item in tags: for area in areas: print(' It inside areasss') search_term = item.name + ' ' + str(area) + ' ' + city search_maps(search_term , "") tag_obj = Tag.query.filter_by(id=int(item.id)).first() for r in place_id_list: name ,address ,phone , website = get_contact(r) try: new_data = Contact(name, phone, "",address,website , city_obj) new_data.tag_contact.append(tag_obj) db.session.add(new_data) db.session.commit() except IntegrityError as e: db.session.rollback() pass except Exception as e: db.session.rollback() print(str(e)) pass scraper.status = "done" db.session.commit()
def upload_contact(): file = request.files['file'] tags = json.loads(request.form['data']) try: if file: filename = file.filename foldertemp = os.path.join(UPLOAD_FOLDER, 'contacts') if os.path.exists(foldertemp): filetemp = os.path.join(foldertemp, filename) file.save(filetemp) else: os.makedirs(foldertemp) filetemp = os.path.join(foldertemp, filename) file.save(filetemp) with open(filetemp, mode="r") as csv_file: csv_data = list(csv.reader(csv_file, delimiter=",")) for item in csv_data: name = item[0] + '-' + item[1] contact_one = str(item[6]) contact_two = str(item[7]) address = str(item[2]) city = item[3].lower() state = item[4] country = item[5] email = item[8] tag = tags city = city.split('-')[0].split('(')[0] if len(contact_one) == 10: contact_one = '91' + contact_one if city == "": if state == "": city = country else: city = state # Checks for empty values if item[0] is not "": try: city_obj = City.query.filter_by( name=str(city)).first() if city_obj: pass else: city_obj = City(str(city), str(state), str(country)) db.session.add(city_obj) con_obj = Contact(name, contact_one, contact_two, address, email, city_obj) db.session.add(con_obj) for item in tag: tag_obj = Tag.query.filter_by( name=item['name']).first() if tag_obj: pass else: pass tag_obj = Tag(str(item['name'])) db.session.add(tag_obj) con_obj.tag_contact.append(tag_obj) db.session.commit() except IntegrityError as e: db.session.rollback() print('Duplicate ----- ' + name, city) pass except Exception as e: db.session.rollback() print('Oh No ---------', name, city) pass else: pass return jsonify({'success': 'Data Added'}) except Exception as e: # return Exception for duplicate data print(str(e)) return jsonify({'message': 'Returns error'})
def onCompletion(self, text): self.after(loads(text))