-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrape.py
38 lines (28 loc) · 937 Bytes
/
scrape.py
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
from pymongo import MongoClient
from logger import logger
def db_results(icao24):
client = MongoClient('localhost:27017')
db = client.AircraftData
result = db.Registration.find_one({
'icao': icao24.upper()
})
if not result:
return None
airline = result['operator'].encode('ascii')
reg_no = result['regid'].encode('ascii')
aircraft = result['type'].encode('ascii')
return reg_no, aircraft, airline
def flight_info(flight):
results = db_results(flight['icao24'])
if not results:
logger.info('could find flight in db (flight={})'.format(flight))
return None
reg_no, aircraft, airline = results
aircraft = ''.join(aircraft.split('-')[:-1])
data = {
'aircraft': aircraft,
'airline': airline
}
if not reg_no:
logger.info('couldn\'t find aircraft icao ({}) in db'.format(flight['icao24']))
return data