def get_sentiment_user(self, db, date_begin, date_end): db = CloudantDatabase(self.client, db, partitioned=False) days = get_days(date_begin, date_end) while not db.exists(): time.sleep(0.1) results = {'negative': 0, 'neutral': 0, 'positive': 0} cou = 0 hash_count = {} related = 0 hash_cou = 0 for tweet_data in db: results[tweet_data['simple_sentiment_label']] += 1 cou += 1 flag = 0 for hash in tweet_data['hashtags']: hash_cou += 1 hash = hash.lower() if 'covid' in hash or 'corona' in hash or ('19' in hash and 'co' in hash) \ or 'home' in hash or 'lock' in hash or 'safe' in hash: flag = 1 hash_count[hash] = hash_count.get(hash, 0) + 1 related += flag results['count'] = cou results['hashtags'] = sorted(hash_count.items(), key=lambda item: item[1], reverse=True) results['coronavirus_related'] = related results['hashtag_count'] = hash_cou db.delete() return results
def get_user_tasks(self, emailAddress): database = CloudantDatabase( self.client, self.app.config['CLOUDANT_NOSQL_DB_REQUEST_DATABASE_NAME']) if not database.exists(): database = self.client.create_database( self.app.config['CLOUDANT_NOSQL_DB_REQUEST_DATABASE_NAME']) selector = {'user': {'$eq': emailAddress}} try: res = database.get_query_result(selector) except Exception as e: raise else: return res
def write_to_schedule(self, schedule_record): database = CloudantDatabase( self.client, self.app.config['CLOUDANT_NOSQL_DB_SCHEDULE_DATABASE_NAME']) append_info = { "status": 'active', "failure_counts": "0", "submit time": time.ctime() } new_document = schedule_record.copy() new_document.update(append_info) if database.exists(): database.create_document(new_document) else: database = self.client.create_database( self.app.config['CLOUDANT_NOSQL_DB_SCHEDULE_DATABASE_NAME']) database.create_document(new_document)
def write_to_request(self, document, user=None, status=None): database = CloudantDatabase( self.client, self.app.config['CLOUDANT_NOSQL_DB_REQUEST_DATABASE_NAME']) append_info = { "user": user, "status": status, "failure_counts": "0", "submit time": time.ctime() } new_document = document.copy() new_document.update(append_info) if database.exists(): database.create_document(new_document) else: database = self.client.create_database( self.app.config['CLOUDANT_NOSQL_DB_REQUEST_DATABASE_NAME']) database.create_document(new_document)
def write_to_mail(self, to, sender, subject, confirm_link, requester): database = CloudantDatabase( self.client, self.app.config['CLOUDANT_NOSQL_DB_MAIL_DATABASE_NAME']) doc = { "to": to, "sender": sender, "subject": subject, "confirm_link": confirm_link, "requester": requester, "status": 'submitted', "submit time": time.ctime() } if database.exists(): database.create_document(doc) else: database = self.client.create_database( self.app.config['CLOUDANT_NOSQL_DB_MAIL_DATABASE_NAME']) database.create_document(doc)
def patient_details(): if (request.method == "POST"): allergies = request.form["allergies"] immunizations = request.form["immunizations"] observations = request.form["observations"] procedures = request.form["procedures"] careplans = request.form["careplans"] medications = request.form["medications"] current = request.form["current"] #flash("Patient Details Successfully Updated !!!",category="success") ## code to store this info in the database username = "******" apikey = "HAltxJaD5Sr4VsbAVB4-rYLfWdrWOkW0fWuqzQFP_Ra_" client = Cloudant.iam(username, apikey, connect=True) db_name = "patient_details" p_details = CloudantDatabase(client, db_name) date_v = str(date.today()) encounter_id = str(session["user_id"]) + '_' + date_v if p_details.exists(): patient_document = { "allergies": allergies, "immunizations": immunizations, "observations": observations, "procedures": procedures, "careplans": careplans, "medications": medications, "current": current, "encounter_id": encounter_id, "date": date_v } p_details.create_document(patient_document) #flash("Data Added Successfully !") client.disconnect() flash("Patient Details Successfully Updated !!!", category="success") return redirect(url_for("patient_details")) return render_template("p_details.html")
def init_user(self, userinfo, status='active'): database = CloudantDatabase( self.client, self.app.config['CLOUDANT_NOSQL_DB_USER_DATABASE_NAME']) doc = { "emailAddress": userinfo.get('emailAddress'), "firstName": userinfo.get('firstName'), "lastName": userinfo.get('lastName'), "uid": userinfo.get('uid'), "approved_country_accesses": None, "approved_company_accesses": None, "pending_country_accesses": None, "pending_company_accesses": None, "status": status, "init time": time.ctime() } if database.exists(): database.create_document(doc) else: return False