-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaverage_calculation.py
More file actions
78 lines (66 loc) · 1.98 KB
/
average_calculation.py
File metadata and controls
78 lines (66 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# -*- coding: utf-8 -*-
"""Python auto.ria.com API.
Python implementation of API intended for calulating
average used car prices that are sold on http://auto.ria.com
Sample API usage:
categories = api.get_categories()
cars_category = select_item('Легковые', categories)
print(api.get_gearboxes(cars_category))
print(api.get_driver_types(cars_category))
print(api.get_options(cars_category))
print(api.get_fuels())
print(api.get_colors())
"""
import os
from math import ceil
from pprint import pprint
from autoria.api import RiaAPI, RiaAverageCarPrice
# not implemented yet
# VEHICLE_MIN_PRICE = '4000'
# VEHICLE_MAX_PRICE = '5000'
# Type, mark and model are required parameters
# the rest of them is optional
api = RiaAPI()
search_params = {
'api_key': os.environ.get('API_KEY'),
'category': 'Легковые',
'mark': 'Mazda',
'model': 'CX-5',
'bodystyle': 'Внедорожник / Кроссовер',
# 'years': [2015, 2017],
# 'state': 'Винницкая',
# 'city': 'Винница',
# 'gears': ['Автомат'],
# 'opts': ['ABS'],
# 'mileage': [10, 200],
# 'fuels': ['Дизель'],
# 'drives': ['Полный'],
# 'color': 'Серый',
# 'engine_volume': 1.5,
# 'seats': 5,
# 'doors': 3,
# 'carrying': 1500,
# 'custom': False,
# 'damage': False,
# 'under_credit': False,
# 'confiscated': False,
# 'on_repair_parts': False
}
myCarAveragePrice = RiaAverageCarPrice(**search_params)
base_url = "https://auto.ria.com/auto_{}_{}_{}.html"
average = myCarAveragePrice.get_average()
search_params.pop("api_key", None)
report = {
"search_params": search_params,
"average": average,
"classifieds_urls": [
[
"${}".format(ceil(price)),
base_url.format(
search_params["mark"].lower(), search_params["model"].lower(), item
),
]
for price, item in zip(average.get("prices"), average.get("classifieds"))
],
}
pprint(report)