import falcon, json, pymongo


MONGO_DB_USER_FILE = '/home/frank/word_cloud-backend/config/mongodb-user'
mongo_db_user_config = open(MONGO_DB_USER_FILE, 'r').read()


user_name = mongo_db_user_config.split(':')[0]
password = mongo_db_user_config.split(':')[1]


mongo_db_client = pymongo.MongoClient('wordcloud-mongo.home.franks-reich.net', 27017)
mongo_db_client.admin.authenticate(user_name, password)
wordcloud_database = mongo_db_client.wordcloud


class WordCloudResource:
    def on_get(self, request, response, name):
        """Handles GET requests"""
        wordcloud = {
            'name': name,
            'wordcloud' : {
                'blub' : 40,
                'blah' : 34,
                'derp' : 57
            }
        }
        response.body = json.dumps(wordcloud)


app = falcon.API()
app.add_route('/wordcloud/{name}', WordCloudResource())

import falcon, json, pymongo


MONGO_DB_USER_FILE = '/home/frank/word_cloud-backend/config/mongodb-user'
mongo_db_user_config = open(MONGO_DB_USER_FILE, 'r').read()


user_name = mongo_db_user_config.rstrip('\n').split(':')[0]
password = mongo_db_user_config.rstrip('\n').split(':')[1]


mongo_db_client = pymongo.MongoClient('wordcloud-mongo.home.franks-reich.net', 27017)
mongo_db_client.admin.authenticate(user_name, password)
wordcloud_database = mongo_db_client.wordcloud


class WordCloudResource:
    def on_get(self, request, response, name):
        """Handles GET requests"""
        wordcloud = {
            'name': name,
            'wordcloud' : {
                'blub' : 40,
                'blah' : 34,
                'derp' : 57
            }
        }
        response.body = json.dumps(wordcloud)


app = falcon.API()
app.add_route('/wordcloud/{name}', WordCloudResource())

Read mongo user and passwd from config file
Read mongo user and passwd from config file

  import falcon, json, pymongo
  
  
  MONGO_DB_USER_FILE = '/home/frank/word_cloud-backend/config/mongodb-user'
  mongo_db_user_config = open(MONGO_DB_USER_FILE, 'r').read()
  
  
- user_name = mongo_db_user_config.split(':')[0]
+ user_name = mongo_db_user_config.rstrip('\n').split(':')[0]
- password = mongo_db_user_config.split(':')[1]
+ password = mongo_db_user_config.rstrip('\n').split(':')[1]
  
  
  mongo_db_client = pymongo.MongoClient('wordcloud-mongo.home.franks-reich.net', 27017)
  mongo_db_client.admin.authenticate(user_name, password)
  wordcloud_database = mongo_db_client.wordcloud
  
  
  class WordCloudResource:
      def on_get(self, request, response, name):
          """Handles GET requests"""
          wordcloud = {
              'name': name,
              'wordcloud' : {
                  'blub' : 40,
                  'blah' : 34,
                  'derp' : 57
              }
          }
          response.body = json.dumps(wordcloud)
  
  
  app = falcon.API()
  app.add_route('/wordcloud/{name}', WordCloudResource())
  
Read mongo user and passwd from config file
## Code Before:
import falcon, json, pymongo


MONGO_DB_USER_FILE = '/home/frank/word_cloud-backend/config/mongodb-user'
mongo_db_user_config = open(MONGO_DB_USER_FILE, 'r').read()


user_name = mongo_db_user_config.split(':')[0]
password = mongo_db_user_config.split(':')[1]


mongo_db_client = pymongo.MongoClient('wordcloud-mongo.home.franks-reich.net', 27017)
mongo_db_client.admin.authenticate(user_name, password)
wordcloud_database = mongo_db_client.wordcloud


class WordCloudResource:
    def on_get(self, request, response, name):
        """Handles GET requests"""
        wordcloud = {
            'name': name,
            'wordcloud' : {
                'blub' : 40,
                'blah' : 34,
                'derp' : 57
            }
        }
        response.body = json.dumps(wordcloud)


app = falcon.API()
app.add_route('/wordcloud/{name}', WordCloudResource())

## Instruction:
Read mongo user and passwd from config file
## Code After:
import falcon, json, pymongo


MONGO_DB_USER_FILE = '/home/frank/word_cloud-backend/config/mongodb-user'
mongo_db_user_config = open(MONGO_DB_USER_FILE, 'r').read()


user_name = mongo_db_user_config.rstrip('\n').split(':')[0]
password = mongo_db_user_config.rstrip('\n').split(':')[1]


mongo_db_client = pymongo.MongoClient('wordcloud-mongo.home.franks-reich.net', 27017)
mongo_db_client.admin.authenticate(user_name, password)
wordcloud_database = mongo_db_client.wordcloud


class WordCloudResource:
    def on_get(self, request, response, name):
        """Handles GET requests"""
        wordcloud = {
            'name': name,
            'wordcloud' : {
                'blub' : 40,
                'blah' : 34,
                'derp' : 57
            }
        }
        response.body = json.dumps(wordcloud)


app = falcon.API()
app.add_route('/wordcloud/{name}', WordCloudResource())
