Exemplo n.º 1
0
def create_server():
    '''Создает сервер типа farhub '''
    if (API_KEY != request.args.get('api')):
        return jsonify({'error': 'Wrong api key'}), 400
    json_data = request.get_json(force=True)

    try:
        srv = Server.objects.get(hash_id=json_data['hash_id'])
        srv.delete()
    except Exception:
        pass
    finally:
        try:
            coun = Country.objects.get(name=json_data['location'])
        except:
            coun = Country(name=json_data['location'])
            coun.save()
        try:
            server_name = Type_Of_Server.objects.get(
                type_of_server='gtn_farhub')
        except:
            server_name = Type_Of_Server(type_of_server='gtn_farhub')
            server_name.save()
        server = Server(type_of_server=server_name,
                        address=json_data['server_ip'],
                        location=coun,
                        api_key=json_data['api_key'],
                        data=json_data['data'],
                        description=json_data['description'],
                        hash_id=json_data['hash_id'])
        server.save()
        Country.synhro()
        monitoring_service()
        return '200 OK'
Exemplo n.º 2
0
def save_country_from_row(review_row):
    country = Country()
    country.country_name = review_row[0]
    country.country_code = review_row[1]
    country.iso_codes = review_row[2]
    country.population = review_row[3]
    country.area = review_row[4]
    country.gdp = review_row[5]
    country.save()
Exemplo n.º 3
0
def backend(request):
    context = {}
    context['ajout'] = False
    if request.method == 'POST':
        pays = request.POST.get("pays", "")
        newPays = Country(name=pays, date=timezone.now())
        newPays.save()
        context['ajout'] = True
    return render(request, 'backend.html', context)
Exemplo n.º 4
0
    def parse(self, **kwargs):
        worksheet = GoogleSheetsParser.get_worksheet(self, '1Mp9r7CNxVnKip-tLAFpbGp4K_MY2iUrbrBOQBcsKLVE')

        i = 2
        while True:
            values_list = worksheet.row_values(i)
            i += 1

            if not values_list[0]:
                break

            try:
                country = Country.objects.get(
                    name=values_list[4]
                )
            except ObjectDoesNotExist:
                country = Country(
                    name=values_list[4]
                )
                self.country_count += 1
                country.save()

            try:
                region = Region.objects.get(
                    name=values_list[1]
                )
            except ObjectDoesNotExist:
                region = Region(
                    name=values_list[1],
                    country=country
                )
                self.region_count += 1
                region.save()

            try:
                city = City.objects.get(
                    name=values_list[0]
                )
            except ObjectDoesNotExist:
                city = City(
                    name=values_list[0],
                    lat=values_list[2],
                    lon=values_list[3],
                    region=region
                )
                self.city_count += 1
                city.save()

        return [
            'New Countries: ' + str(self.country_count),
            'New Regions: ' + str(self.region_count),
            'New Cities: ' + str(self.city_count),
        ]
Exemplo n.º 5
0
def create_country(country_name):
    '''Создает страну'''
    if (API_KEY != request.args.get('api')):
        return jsonify({'error': 'Wrong api key'}), 400
    if country_name is None or not country_name:
        return 'Incorrect Query'
    try:
        country = Country.objects.get(name=country_name)
        return 'Объект существует'
    except Exception:
        country = Country(name=country_name)
        country.save()
    return '200 OK'
Exemplo n.º 6
0
    def parse(self, **kwargs):
        worksheet = GoogleSheetsParser.get_worksheet(self, '15Q8sDyG_eBUHMcriIAHTmwDcdSdJSSLNAo34iBZKyJk')

        i = 2
        while True:
            values_list = worksheet.row_values(i)
            i += 1

            if not values_list[0]:
                break

            if values_list[5] == kwargs['options']['wave']:
                try:
                    university = University.objects.get(
                        name=values_list[0]
                    )
                except ObjectDoesNotExist:
                    try:
                        city = City.objects.get(
                            name=values_list[3]
                        )
                    except ObjectDoesNotExist:
                        try:
                            region = Region.objects.get(
                                name='unknown'
                            )
                        except ObjectDoesNotExist:
                            try:
                                country = Country.objects.get(
                                    name=values_list[2]
                                )
                            except ObjectDoesNotExist:
                                country = Country(
                                    name=values_list[2]
                                )
                                country.save()
                            region = Region(
                                name='unknown',
                                country=country,
                            )
                            self.unknown_region = True
                            region.save()
                        city = City(
                            name=values_list[3],
                            region=region,
                            lat=0,
                            lon=0
                        )
                        self.city_count += 1
                        city.save()

                    university = University(
                        name=values_list[0],
                        abbr=values_list[1],
                        city=city,
                        site=values_list[4]
                    )
                    self.university_count += 1
                    university.save()

        result = [
            'Wave ' + str(kwargs['options']['wave']),
            'New University: ' + str(self.university_count),
        ]
        if self.city_count > 0:
            result.append('------')
            result.append('Check this situation! It is not normal!')
            result.append('------')
            result.append('New City: ' + str(self.city_count))
            if self.unknown_region:
                result.append('Added Region "unknown"')

        return result
Exemplo n.º 7
0
def index(request):
    russia = Country(name="France", date=timezone.now())
    russia.save()
    return HttpResponse("Hi, world. You're at the app index.")