Esempio n. 1
0
    def handle(self, *args, **options):

        if options['update']:
            self.check_settings_exist()
            self.set_cosmos_client()

            version = self.get_latest_version_number()
            num_institutions = self.get_number_of_institutions(version)
            institutions_list = self.get_institutions(version)

            with open(self.fixture_file, 'w') as outfile:
                json.dump(institutions_list, outfile, indent=4)
                self.success('Saved file to ' + self.fixture_file)
                outfile.close()

        else:
            with open(self.fixture_file, 'r') as file:
                contents = json.load(file)

                self.mongo = Mongo('institutions')
                self.mongo.collection_delete()

                try:
                    self.mongo.insert(contents)
                    self.success('Inserted institutions into MongoDB')
                except Exception as e:
                    message = e.message if hasattr(e, 'message') else \
                        'Failed to insert institutions into MongoDB'
                    raise CommandError(message)
Esempio n. 2
0
 def populate_mongodb(self):
     if settings.MONGODB_HOST == self.mongo_host and \
        settings.MONGODB_USERNAME == self.mongo_username and \
        settings.MONGODB_PASSWORD == self.mongo_password:
         mongo = Mongo('institutions')
         result = mongo.get_one(
             {'institution_id': str(self.institution_id)})
         if result is None:
             management.call_command('populate_institutions')
             management.call_command('populate_courses')
Esempio n. 3
0
def load_institution_data(institution_id):

    if settings.LOCAL:
        return InstitutionMocks.get_successful_institution_load_response()
    if settings.MONGODB_HOST:
        mongo = Mongo('institutions')
        return mongo.get_one({'institution_id': str(institution_id)})
    else:
        headers = {'Ocp-Apim-Subscription-Key': settings.DATASETAPIKEY}
        base_url = "%s/institutions/%s"

        return requests.get(url=base_url %
                            (settings.DATASETAPIHOST, institution_id),
                            headers=headers)
Esempio n. 4
0
File: aivb.py Progetto: cmry/gomi
 def __route_mongo(self, sw):
     args, db = self.args, Mongo(self.log, sw)
     if args['load'] and args['-a']:
         db.load()
     elif args['load'] and args['--slice']:
         db.load(int(args['--slice']))
     elif args['search']:
         print "Output: %s" % [
             x for x in db.search('search', args['--key'], args['--value'])
         ]
     elif args['retr']:
         print "Output: %s" % [
             x for x in db.search('select_exists', args['--key'], None,
                                  args['--value'], None)
         ]
     elif args['del']:
         db.clear_all(True if args['-x'] else False)
def load_course_data(institution_id, course_id, mode):
    if settings.LOCAL:
        if course_id == "GN12":
            return JointCourseFormatMocks.get_successful_course_load_response()
        return CourseFormatMocks.get_successful_course_load_response()
    if settings.MONGODB_HOST:
        mongo = Mongo('courses')
        return mongo.get_one({
            'institution_id': str(institution_id),
            'course_id': str(course_id),
        })
    else:
        headers = {'Ocp-Apim-Subscription-Key': settings.DATASETAPIKEY}
        base_url = "%s/institutions/%s/courses/%s/modes/%s"

        response = requests.get(
            url=base_url %
            (settings.DATASETAPIHOST, institution_id, course_id, mode),
            headers=headers)
        return response