def connect_mongodb(): """ 连接mongodb数据库 :return: """ path = os.path.dirname(os.path.abspath(__file__)) MAIN_CONF = path + '/config/gen_scripts_test.cfg' parser = ConfigParser() parser.read(MAIN_CONF) mongodb_host = parser.get('mongodb', 'host') mongodb_db = parser.get('mongodb', 'db') mongodb_user = parser.get('mongodb', 'user') mongodb_password = parser.get('mongodb', 'password') mongodb_authMechanism = parser.get('mongodb', 'authMechanism') mongodb_port = int(parser.get('mongodb', 'port')) client = MongoClient(host=mongodb_host, username=mongodb_user, password=mongodb_password, authSource=mongodb_db, authMechanism=mongodb_authMechanism, port=mongodb_port) database = client.get_database(mongodb_db) return database
# -*- coding: utf-8 -*- import http.client import pymongo import json import datetime import logging import sys uri = 'mongodb://localhost:27017/paparazzi' client = pymongo.MongoClient(uri) db = client.get_database('paparazzi') headers = { 'accept': "application/json", 'apikey': "4c67720b046a4743aba6979181505cef" } paths = ["/kelebek/gurme/", "/kelebek/hayat/", "/kelebek/magazin/", "/kelebek/blog/pinar-oznur/", "/kelebek/televizyon/"] logging.basicConfig( format="%(asctime)s [%(threadName)-8.8s] %(message)s", handlers=[ logging.FileHandler("{0}/{1}.log".format(".", "hurriyetGallery")), logging.StreamHandler(sys.stdout) ])
''' import os import json import http.client, urllib.parse, json import pymongo import sys import re import traceback from _collections import defaultdict import requests uri = "mongodb://*****:*****@acemwpdbpacdb01.documents.azure.com:10255/?ssl=true&replicaSet=globaldb" client = pymongo.MongoClient(uri) language = "en-us" #language = "en-GB" database = client.get_database('BPADB') collection = database.get_collection('FileContent') #data=collection.find_one({"DocumentID": "5b6d87ad9a762129d073a2a5"})#6 data = collection.find_one({"DocumentID": "5b6c49f3e670fa23e8d76c6e"}) #412 #data=collection.find_one({"DocumentID": "5b714bcb9a762129d073a2e0"})#11 pages = data['Content']['pages'] def index_idetifier(txt, tkn, a_idx): for i in re.finditer(re.sub('\W', '\W', tkn), txt[a_idx:]): start_value = a_idx + i.start(0) end_value = a_idx + i.end(0) return ((start_value, end_value)) def extractNER(doc_id):
import os db_user = os.environ.get('db_user') db_password = os.environ.get('db_pass') msg91_authkey = os.environ.get('msg91_authkey') ip_stack = os.environ.get('ip_stack') secret_key = os.environ.get('secret_key') app = Flask(__name__) app.secret_key = secret_key client = MongoClient( f"mongodb+srv://{db_user}:{db_password}@cluster0-jvfen.mongodb.net/test?retryWrites=true&w=majority" ) db = client.get_database('smartOTP') notp_colls = db.notp totp_colls = db.totp suspicious_colls = db.suspicious @app.route('/') def index(): ip = request.remote_addr is_suspicious = helper.is_suspicious(suspicious_colls, ip) if is_suspicious: data = requests.get( f"http://api.ipstack.com/{ip}?access_key={ip_stack}&format=1") return render_template('suspicious.html', data=data)