def __init__(self, bot): threading.Thread.__init__(self) self.db = MongoConnector() self.db.connect(cp['DATABASE']['Address'], cp['DATABASE']['Name']) self.collection = cp['DATABASE']['MonitoringCollection'] self.telegram_bot = bot self.running = True print('Reward crawler started')
def main(): tornado.options.options['logging'] = "INFO" tornado.options.parse_command_line() io_loop = tornado.ioloop.IOLoop.instance() app = make_app() # MongoConnector is our mongodb connector mongo_connector = MongoConnector('test_database', mongo_address=settings.MONGO_ADDRESS) app.mongo_connector = mongo_connector # PikaConnector is our rabbitmq consumer app.pika_connector = PikaConnector( io_loop, mongo_connector, rabbitmq_address=settings.RABBITMQ_ADDRESS) app.pika_connector.run() try: app.listen(8888) io_loop.start() except KeyboardInterrupt: app.pika_connector.stop()
import time import logging import datetime import re # Enable logging logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) logger = logging.getLogger(__name__) cp = ConfigParser() cp.optionxform = str cp.read('../config.ini') db = MongoConnector() db.connect(cp['DATABASE']['Address'], cp['DATABASE']['Name']) blockchain = BlockchainConnector() blockchain.connect(cp['POSTGRES']) monitoring_collection = cp['DATABASE']['MonitoringCollection'] CRAWLER_SLEEP_TIME = 120 NEW_TRANSACTION_MESSAGE_TEMPLATE = 'New transaction for "{}" ({}): {} XSN' telegram_bot_token = cp['TELEGRAM']['SecretKey'] DATE_FORMAT = '%d/%m/%Y %H:%M:%S' ADD_ADDRESS_MESSAGE = 'Enter address for ' ADD_NAME_MESSAGE = 'Enter monitor name'
classifications = clf.predict_proba(transformed) #print("classifications", classifications) sorted_prob_themes = sorted( [(prob, theme_nr) for prob, theme_nr in zip(classifications[0], classes)], reverse=True) sorted_themes = [ int(theme_nr) for (prob, theme_nr) in sorted_prob_themes ] print("Used logistic regression classification") sorted_themes_using_topic_connection = self.rank_according_to_topic_connection( document_id, sorted_themes, potential_theme_dict) for theme in all_theme_nrs: # themes that have no associate documents or description, and therefore aren't classifier ranked, are ranked as last if theme not in sorted_themes_using_topic_connection: sorted_themes_using_topic_connection.append(theme) themes_str = [ str(theme) for theme in sorted_themes_using_topic_connection ] return themes_str if __name__ == '__main__': mc = MongoConnector() ts = ThemeSorter(mc) ts.retrain_model("61ea6c0301c7c1346b1ff9f4") print(ts.rank_themes_for_document("61ea6c0301c7c1346b1ff9f4", "14"))
def get(self): global mongoConnector word_document = mongoConnector.getDocumentByWord( request.args.get("word")[1:-1]) return word_document.guessNextWord() class Ping(Resource): def get(self): return "Alive" if __name__ == "__main__": if len(sys.argv) != 5: print("Usage: problem3.py <host> <port> <database> <collection>") sys.exit(-1) mongoConnector = MongoConnector(sys.argv[1], int(sys.argv[2]), sys.argv[3], sys.argv[4]) app = Flask(__name__) api = Api(app) api.add_resource(Ping, '/') api.add_resource(Next, '/gutenberg/predict/next/') api.add_resource(Guess, '/gutenberg/predict/random/') app.run(debug=True)
import topics2themes.make_topic_models as make_topic_models from topics2themes.mongo_connector import MongoConnector from topics2themes.theme_sorter import ThemeSorter from topics2themes.environment_configuration import * from topics2themes.topic_model_constants import * app = Flask(__name__, template_folder="user_interface") if RUN_LOCALLY: CORS(app) else: app.config['MONGO_CONNECT'] = False try: mongo_con = MongoConnector() except: e = sys.exc_info() print("The following error occurred: ") print(e) print("The pymongo database might not be running") mongo_con = MongoConnector() exit(1) theme_sort = ThemeSorter(mongo_con) # To not have a lot of space in the output app.config['JSONIFY_PRETTYPRINT_REGULAR'] = False def get_more_exception_info(): trace_back = traceback.format_exc()