docstring
stringlengths
52
499
function
stringlengths
67
35.2k
__index_level_0__
int64
52.6k
1.16M
Handle changes to the forwarded IPs on a network interface. Args: interface: string, the output device to configure. forwarded_ips: list, the forwarded IP address strings desired. interface_ip: string, current interface ip address.
def HandleForwardedIps(self, interface, forwarded_ips, interface_ip=None): desired = self.ip_forwarding_utils.ParseForwardedIps(forwarded_ips) configured = self.ip_forwarding_utils.GetForwardedIps( interface, interface_ip) to_add = sorted(set(desired) - set(configured)) to_remove = sorted(set(configured) - set(desired)) self._LogForwardedIpChanges( configured, desired, to_add, to_remove, interface) self._AddForwardedIps(to_add, interface) self._RemoveForwardedIps(to_remove, interface)
243,032
Enable the list of network interfaces. Args: interfaces: list of string, the output device names to enable. logger: logger object, used to write to SysLog and serial port. dhclient_script: string, the path to a dhclient script used by dhclient.
def EnableNetworkInterfaces( self, interfaces, logger, dhclient_script=None): interfaces_to_up = [i for i in interfaces if i != 'eth0'] if interfaces_to_up: logger.info('Enabling the Ethernet interfaces %s.', interfaces_to_up) self._WriteIfcfg(interfaces_to_up, logger) self._Ifup(interfaces_to_up, logger)
243,033
Write ifcfg files for multi-NIC support. Overwrites the files. This allows us to update ifcfg-* in the future. Disable the network setup to override this behavior and customize the configurations. Args: interfaces: list of string, the output device names to enable. logger: logger object, used to write to SysLog and serial port.
def _WriteIfcfg(self, interfaces, logger): for interface in interfaces: interface_config = os.path.join( self.network_path, 'ifcfg-%s' % interface) interface_content = [ '# Added by Google.', 'STARTMODE=hotplug', 'BOOTPROTO=dhcp', 'DHCLIENT_SET_DEFAULT_ROUTE=yes', 'DHCLIENT_ROUTE_PRIORITY=10%s00' % interface, '', ] with open(interface_config, 'w') as interface_file: interface_file.write('\n'.join(interface_content)) logger.info('Created ifcfg file for interface %s.', interface)
243,034
Activate network interfaces. Args: interfaces: list of string, the output device names to enable. logger: logger object, used to write to SysLog and serial port.
def _Ifup(self, interfaces, logger): ifup = ['/usr/sbin/wicked', 'ifup', '--timeout', '1'] try: subprocess.check_call(ifup + interfaces) except subprocess.CalledProcessError: logger.warning('Could not activate interfaces %s.', interfaces)
243,035
Called when network interface metadata changes. Args: result: dict, the metadata response with the network interfaces.
def HandleNetworkInterfaces(self, result): network_interfaces = self._ExtractInterfaceMetadata(result) if self.network_setup_enabled: self.network_setup.EnableNetworkInterfaces( [interface.name for interface in network_interfaces[1:]]) for interface in network_interfaces: if self.ip_forwarding_enabled: self.ip_forwarding.HandleForwardedIps( interface.name, interface.forwarded_ips, interface.ip)
243,038
Extracts network interface metadata. Args: metadata: dict, the metadata response with the new network interfaces. Returns: list, a list of NetworkInterface objects.
def _ExtractInterfaceMetadata(self, metadata): interfaces = [] for network_interface in metadata: mac_address = network_interface.get('mac') interface = self.network_utils.GetNetworkInterface(mac_address) ip_addresses = [] if interface: ip_addresses.extend(network_interface.get('forwardedIps', [])) if self.ip_aliases: ip_addresses.extend(network_interface.get('ipAliases', [])) if self.target_instance_ips: ip_addresses.extend(network_interface.get('targetInstanceIps', [])) interfaces.append(NetworkDaemon.NetworkInterface( interface, ip_addresses, network_interface.get('ip', []))) else: message = 'Network interface not found for MAC address: %s.' self.logger.warning(message, mac_address) return interfaces
243,039
Aircraft category number Args: msg (string): 28 bytes hexadecimal message string Returns: int: category number
def category(msg): if common.typecode(msg) < 1 or common.typecode(msg) > 4: raise RuntimeError("%s: Not a identification message" % msg) msgbin = common.hex2bin(msg) return common.bin2int(msgbin[5:8])
243,076
Aircraft callsign Args: msg (string): 28 bytes hexadecimal message string Returns: string: callsign
def callsign(msg): if common.typecode(msg) < 1 or common.typecode(msg) > 4: raise RuntimeError("%s: Not a identification message" % msg) chars = '#ABCDEFGHIJKLMNOPQRSTUVWXYZ#####_###############0123456789######' msgbin = common.hex2bin(msg) csbin = msgbin[40:96] cs = '' cs += chars[common.bin2int(csbin[0:6])] cs += chars[common.bin2int(csbin[6:12])] cs += chars[common.bin2int(csbin[12:18])] cs += chars[common.bin2int(csbin[18:24])] cs += chars[common.bin2int(csbin[24:30])] cs += chars[common.bin2int(csbin[30:36])] cs += chars[common.bin2int(csbin[36:42])] cs += chars[common.bin2int(csbin[42:48])] # clean string, remove spaces and marks, if any. # cs = cs.replace('_', '') cs = cs.replace('#', '') return cs
243,077
Decode airborn position from a pair of even and odd position message Args: msg0 (string): even message (28 bytes hexadecimal string) msg1 (string): odd message (28 bytes hexadecimal string) t0 (int): timestamps for the even message t1 (int): timestamps for the odd message Returns: (float, float): (latitude, longitude) of the aircraft
def airborne_position(msg0, msg1, t0, t1): mb0 = common.hex2bin(msg0)[32:] mb1 = common.hex2bin(msg1)[32:] # 131072 is 2^17, since CPR lat and lon are 17 bits each. cprlat_even = common.bin2int(mb0[22:39]) / 131072.0 cprlon_even = common.bin2int(mb0[39:56]) / 131072.0 cprlat_odd = common.bin2int(mb1[22:39]) / 131072.0 cprlon_odd = common.bin2int(mb1[39:56]) / 131072.0 air_d_lat_even = 360.0 / 60 air_d_lat_odd = 360.0 / 59 # compute latitude index 'j' j = common.floor(59 * cprlat_even - 60 * cprlat_odd + 0.5) lat_even = float(air_d_lat_even * (j % 60 + cprlat_even)) lat_odd = float(air_d_lat_odd * (j % 59 + cprlat_odd)) if lat_even >= 270: lat_even = lat_even - 360 if lat_odd >= 270: lat_odd = lat_odd - 360 # check if both are in the same latidude zone, exit if not if common.cprNL(lat_even) != common.cprNL(lat_odd): return None # compute ni, longitude index m, and longitude if (t0 > t1): lat = lat_even nl = common.cprNL(lat) ni = max(common.cprNL(lat)- 0, 1) m = common.floor(cprlon_even * (nl-1) - cprlon_odd * nl + 0.5) lon = (360.0 / ni) * (m % ni + cprlon_even) else: lat = lat_odd nl = common.cprNL(lat) ni = max(common.cprNL(lat) - 1, 1) m = common.floor(cprlon_even * (nl-1) - cprlon_odd * nl + 0.5) lon = (360.0 / ni) * (m % ni + cprlon_odd) if lon > 180: lon = lon - 360 return round(lat, 5), round(lon, 5)
243,078
Decode airborne position with only one message, knowing reference nearby location, such as previously calculated location, ground station, or airport location, etc. The reference position shall be with in 180NM of the true position. Args: msg (string): even message (28 bytes hexadecimal string) lat_ref: previous known latitude lon_ref: previous known longitude Returns: (float, float): (latitude, longitude) of the aircraft
def airborne_position_with_ref(msg, lat_ref, lon_ref): mb = common.hex2bin(msg)[32:] cprlat = common.bin2int(mb[22:39]) / 131072.0 cprlon = common.bin2int(mb[39:56]) / 131072.0 i = int(mb[21]) d_lat = 360.0/59 if i else 360.0/60 j = common.floor(lat_ref / d_lat) \ + common.floor(0.5 + ((lat_ref % d_lat) / d_lat) - cprlat) lat = d_lat * (j + cprlat) ni = common.cprNL(lat) - i if ni > 0: d_lon = 360.0 / ni else: d_lon = 360.0 m = common.floor(lon_ref / d_lon) \ + common.floor(0.5 + ((lon_ref % d_lon) / d_lon) - cprlon) lon = d_lon * (m + cprlon) return round(lat, 5), round(lon, 5)
243,079
Decode aircraft altitude Args: msg (string): 28 bytes hexadecimal message string Returns: int: altitude in feet
def altitude(msg): tc = common.typecode(msg) if tc<9 or tc==19 or tc>22: raise RuntimeError("%s: Not a airborn position message" % msg) mb = common.hex2bin(msg)[32:] if tc < 19: # barometric altitude q = mb[15] if q: n = common.bin2int(mb[8:15]+mb[16:20]) alt = n * 25 - 1000 else: alt = None else: # GNSS altitude, meters -> feet alt = common.bin2int(mb[8:20]) * 3.28084 return alt
243,080
Mode-S Cyclic Redundancy Check Detect if bit error occurs in the Mode-S message Args: msg (string): 28 bytes hexadecimal message string encode (bool): True to encode the date only and return the checksum Returns: string: message checksum, or partity bits (encoder)
def crc(msg, encode=False): # the polynominal generattor code for CRC [1111111111111010000001001] generator = np.array([1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,0,0,0,0,0,1,0,0,1]) ng = len(generator) msgnpbin = bin2np(hex2bin(msg)) if encode: msgnpbin[-24:] = [0] * 24 # loop all bits, except last 24 piraty bits for i in range(len(msgnpbin)-24): if msgnpbin[i] == 0: continue # perform XOR, when 1 msgnpbin[i:i+ng] = np.bitwise_xor(msgnpbin[i:i+ng], generator) # last 24 bits reminder = np2bin(msgnpbin[-24:]) return reminder
243,082
Calculate the ICAO address from an Mode-S message with DF4, DF5, DF20, DF21 Args: msg (String): 28 bytes hexadecimal message string Returns: String: ICAO address in 6 bytes hexadecimal string
def icao(msg): DF = df(msg) if DF in (11, 17, 18): addr = msg[2:8] elif DF in (0, 4, 5, 16, 20, 21): c0 = bin2int(crc(msg, encode=True)) c1 = hex2int(msg[-6:]) addr = '%06X' % (c0 ^ c1) else: addr = None return addr
243,083
Computes identity (squawk code) from DF5 or DF21 message, bit 20-32. credit: @fbyrkjeland Args: msg (String): 28 bytes hexadecimal message string Returns: string: squawk code
def idcode(msg): if df(msg) not in [5, 21]: raise RuntimeError("Message must be Downlink Format 5 or 21.") mbin = hex2bin(msg) C1 = mbin[19] A1 = mbin[20] C2 = mbin[21] A2 = mbin[22] C4 = mbin[23] A4 = mbin[24] # _ = mbin[25] B1 = mbin[26] D1 = mbin[27] B2 = mbin[28] D2 = mbin[29] B4 = mbin[30] D4 = mbin[31] byte1 = int(A4+A2+A1, 2) byte2 = int(B4+B2+B1, 2) byte3 = int(C4+C2+C1, 2) byte4 = int(D4+D2+D1, 2) return str(byte1) + str(byte2) + str(byte3) + str(byte4)
243,086
Computes the altitude from DF4 or DF20 message, bit 20-32. credit: @fbyrkjeland Args: msg (String): 28 bytes hexadecimal message string Returns: int: altitude in ft
def altcode(msg): if df(msg) not in [0, 4, 16, 20]: raise RuntimeError("Message must be Downlink Format 0, 4, 16, or 20.") # Altitude code, bit 20-32 mbin = hex2bin(msg) mbit = mbin[25] # M bit: 26 qbit = mbin[27] # Q bit: 28 if mbit == '0': # unit in ft if qbit == '1': # 25ft interval vbin = mbin[19:25] + mbin[26] + mbin[28:32] alt = bin2int(vbin) * 25 - 1000 if qbit == '0': # 100ft interval, above 50175ft C1 = mbin[19] A1 = mbin[20] C2 = mbin[21] A2 = mbin[22] C4 = mbin[23] A4 = mbin[24] # _ = mbin[25] B1 = mbin[26] # D1 = mbin[27] # always zero B2 = mbin[28] D2 = mbin[29] B4 = mbin[30] D4 = mbin[31] graystr = D2 + D4 + A1 + A2 + A4 + B1 + B2 + B4 + C1 + C2 + C4 alt = gray2alt(graystr) if mbit == '1': # unit in meter vbin = mbin[19:25] + mbin[26:31] alt = int(bin2int(vbin) * 3.28084) # convert to ft return alt
243,087
check if the data bits are all zeros Args: msg (String): 28 bytes hexadecimal message string Returns: bool: True or False
def allzeros(msg): d = hex2bin(data(msg)) if bin2int(d) > 0: return False else: return True
243,090
Check if a message is likely to be BDS code 2,0 Args: msg (String): 28 bytes hexadecimal message string Returns: bool: True or False
def is30(msg): if allzeros(msg): return False d = hex2bin(data(msg)) if d[0:8] != '00110000': return False # threat type 3 not assigned if d[28:30] == '11': return False # reserved for ACAS III, in far future if bin2int(d[15:22]) >= 48: return False return True
243,096
Decode position from a pair of even and odd position message (works with both airborne and surface position messages) Args: msg0 (string): even message (28 bytes hexadecimal string) msg1 (string): odd message (28 bytes hexadecimal string) t0 (int): timestamps for the even message t1 (int): timestamps for the odd message Returns: (float, float): (latitude, longitude) of the aircraft
def position(msg0, msg1, t0, t1, lat_ref=None, lon_ref=None): tc0 = typecode(msg0) tc1 = typecode(msg1) if (5<=tc0<=8 and 5<=tc1<=8): if (not lat_ref) or (not lon_ref): raise RuntimeError("Surface position encountered, a reference \ position lat/lon required. Location of \ receiver can be used.") else: return surface_position(msg0, msg1, t0, t1, lat_ref, lon_ref) elif (9<=tc0<=18 and 9<=tc1<=18): # Airborne position with barometric height return airborne_position(msg0, msg1, t0, t1) elif (20<=tc0<=22 and 20<=tc1<=22): # Airborne position with GNSS height return airborne_position(msg0, msg1, t0, t1) else: raise RuntimeError("incorrect or inconsistant message types")
243,097
Decode aircraft altitude Args: msg (string): 28 bytes hexadecimal message string Returns: int: altitude in feet
def altitude(msg): tc = typecode(msg) if tc<5 or tc==19 or tc>22: raise RuntimeError("%s: Not a position message" % msg) if tc>=5 and tc<=8: # surface position, altitude 0 return 0 msgbin = common.hex2bin(msg) q = msgbin[47] if q: n = common.bin2int(msgbin[40:47]+msgbin[48:52]) alt = n * 25 - 1000 return alt else: return None
243,099
Calculate the speed, heading, and vertical rate (handles both airborne or surface message) Args: msg (string): 28 bytes hexadecimal message string Returns: (int, float, int, string): speed (kt), ground track or heading (degree), rate of climb/descend (ft/min), and speed type ('GS' for ground speed, 'AS' for airspeed)
def velocity(msg): if 5 <= typecode(msg) <= 8: return surface_velocity(msg) elif typecode(msg) == 19: return airborne_velocity(msg) else: raise RuntimeError("incorrect or inconsistant message types, expecting 4<TC<9 or TC=19")
243,100
Get speed and ground track (or heading) from the velocity message (handles both airborne or surface message) Args: msg (string): 28 bytes hexadecimal message string Returns: (int, float): speed (kt), ground track or heading (degree)
def speed_heading(msg): spd, trk_or_hdg, rocd, tag = velocity(msg) return spd, trk_or_hdg
243,101
ADS-B Version Args: msg (string): 28 bytes hexadecimal message string, TC = 31 Returns: int: version number
def version(msg): tc = typecode(msg) if tc != 31: raise RuntimeError("%s: Not a status operation message, expecting TC = 31" % msg) msgbin = common.hex2bin(msg) version = common.bin2int(msgbin[72:75]) return version
243,102
Calculate NUCp, Navigation Uncertainty Category - Position (ADS-B version 1) Args: msg (string): 28 bytes hexadecimal message string, Returns: int: Horizontal Protection Limit int: 95% Containment Radius - Horizontal (meters) int: 95% Containment Radius - Vertical (meters)
def nuc_p(msg): tc = typecode(msg) if typecode(msg) < 5 or typecode(msg) > 22: raise RuntimeError( "%s: Not a surface position message (5<TC<8), \ airborne position message (8<TC<19), \ or airborne position with GNSS height (20<TC<22)" % msg ) try: NUCp = uncertainty.TC_NUCp_lookup[tc] HPL = uncertainty.NUCp[NUCp]['HPL'] RCu = uncertainty.NUCp[NUCp]['RCu'] RCv = uncertainty.NUCp[NUCp]['RCv'] except KeyError: HPL, RCu, RCv = uncertainty.NA, uncertainty.NA, uncertainty.NA if tc in [20, 21]: RCv = uncertainty.NA return HPL, RCu, RCv
243,103
Calculate NUCv, Navigation Uncertainty Category - Velocity (ADS-B version 1) Args: msg (string): 28 bytes hexadecimal message string, Returns: int or string: 95% Horizontal Velocity Error int or string: 95% Vertical Velocity Error
def nuc_v(msg): tc = typecode(msg) if tc != 19: raise RuntimeError("%s: Not an airborne velocity message, expecting TC = 19" % msg) msgbin = common.hex2bin(msg) NUCv = common.bin2int(msgbin[42:45]) try: HVE = uncertainty.NUCv[NUCv]['HVE'] VVE = uncertainty.NUCv[NUCv]['VVE'] except KeyError: HVE, VVE = uncertainty.NA, uncertainty.NA return HVE, VVE
243,104
Calculate NIC, navigation integrity category, for ADS-B version 1 Args: msg (string): 28 bytes hexadecimal message string NICs (int or string): NIC supplement Returns: int or string: Horizontal Radius of Containment int or string: Vertical Protection Limit
def nic_v1(msg, NICs): if typecode(msg) < 5 or typecode(msg) > 22: raise RuntimeError( "%s: Not a surface position message (5<TC<8), \ airborne position message (8<TC<19), \ or airborne position with GNSS height (20<TC<22)" % msg ) tc = typecode(msg) NIC = uncertainty.TC_NICv1_lookup[tc] if isinstance(NIC, dict): NIC = NIC[NICs] try: Rc = uncertainty.NICv1[NIC][NICs]['Rc'] VPL = uncertainty.NICv1[NIC][NICs]['VPL'] except KeyError: Rc, VPL = uncertainty.NA, uncertainty.NA return Rc, VPL
243,105
Calculate NIC, navigation integrity category, for ADS-B version 2 Args: msg (string): 28 bytes hexadecimal message string NICa (int or string): NIC supplement - A NICbc (int or srting): NIC supplement - B or C Returns: int or string: Horizontal Radius of Containment
def nic_v2(msg, NICa, NICbc): if typecode(msg) < 5 or typecode(msg) > 22: raise RuntimeError( "%s: Not a surface position message (5<TC<8), \ airborne position message (8<TC<19), \ or airborne position with GNSS height (20<TC<22)" % msg ) tc = typecode(msg) NIC = uncertainty.TC_NICv2_lookup[tc] if 20<=tc<=22: NICs = 0 else: NICs = NICa*2 + NICbc try: if isinstance(NIC, dict): NIC = NIC[NICs] Rc = uncertainty.NICv2[NIC][NICs]['Rc'] except KeyError: Rc = uncertainty.NA return Rc
243,106
Obtain NIC supplement bit, TC=31 message Args: msg (string): 28 bytes hexadecimal message string Returns: int: NICs number (0 or 1)
def nic_s(msg): tc = typecode(msg) if tc != 31: raise RuntimeError("%s: Not a status operation message, expecting TC = 31" % msg) msgbin = common.hex2bin(msg) nic_s = int(msgbin[75]) return nic_s
243,107
Obtain NICa/c, navigation integrity category supplements a and c Args: msg (string): 28 bytes hexadecimal message string Returns: (int, int): NICa and NICc number (0 or 1)
def nic_a_c(msg): tc = typecode(msg) if tc != 31: raise RuntimeError("%s: Not a status operation message, expecting TC = 31" % msg) msgbin = common.hex2bin(msg) nic_a = int(msgbin[75]) nic_c = int(msgbin[51]) return nic_a, nic_c
243,108
Obtain NICb, navigation integrity category supplement-b Args: msg (string): 28 bytes hexadecimal message string Returns: int: NICb number (0 or 1)
def nic_b(msg): tc = typecode(msg) if tc < 9 or tc > 18: raise RuntimeError("%s: Not a airborne position message, expecting 8<TC<19" % msg) msgbin = common.hex2bin(msg) nic_b = int(msgbin[39]) return nic_b
243,109
Calculate NACp, Navigation Accuracy Category - Position Args: msg (string): 28 bytes hexadecimal message string, TC = 29 or 31 Returns: int or string: 95% horizontal accuracy bounds, Estimated Position Uncertainty int or string: 95% vertical accuracy bounds, Vertical Estimated Position Uncertainty
def nac_p(msg): tc = typecode(msg) if tc not in [29, 31]: raise RuntimeError("%s: Not a target state and status message, \ or operation status message, expecting TC = 29 or 31" % msg) msgbin = common.hex2bin(msg) if tc == 29: NACp = common.bin2int(msgbin[71:75]) elif tc == 31: NACp = common.bin2int(msgbin[76:80]) try: EPU = uncertainty.NACp[NACp]['EPU'] VEPU = uncertainty.NACp[NACp]['VEPU'] except KeyError: EPU, VEPU = uncertainty.NA, uncertainty.NA return EPU, VEPU
243,110
Calculate NACv, Navigation Accuracy Category - Velocity Args: msg (string): 28 bytes hexadecimal message string, TC = 19 Returns: int or string: 95% horizontal accuracy bounds for velocity, Horizontal Figure of Merit int or string: 95% vertical accuracy bounds for velocity, Vertical Figure of Merit
def nac_v(msg): tc = typecode(msg) if tc != 19: raise RuntimeError("%s: Not an airborne velocity message, expecting TC = 19" % msg) msgbin = common.hex2bin(msg) NACv = common.bin2int(msgbin[42:45]) try: HFOMr = uncertainty.NACv[NACv]['HFOMr'] VFOMr = uncertainty.NACv[NACv]['VFOMr'] except KeyError: HFOMr, VFOMr = uncertainty.NA, uncertainty.NA return HFOMr, VFOMr
243,111
Calculate SIL, Surveillance Integrity Level Args: msg (string): 28 bytes hexadecimal message string with TC = 29, 31 Returns: int or string: Probability of exceeding Horizontal Radius of Containment RCu int or string: Probability of exceeding Vertical Integrity Containment Region VPL string: SIL supplement based on per "hour" or "sample", or 'unknown'
def sil(msg, version): tc = typecode(msg) if tc not in [29, 31]: raise RuntimeError("%s: Not a target state and status messag, \ or operation status message, expecting TC = 29 or 31" % msg) msgbin = common.hex2bin(msg) if tc == 29: SIL = common.bin2int(msgbin[76:78]) elif tc == 31: SIL = common.bin2int(msgbin[82:84]) try: PE_RCu = uncertainty.SIL[SIL]['PE_RCu'] PE_VPL = uncertainty.SIL[SIL]['PE_VPL'] except KeyError: PE_RCu, PE_VPL = uncertainty.NA, uncertainty.NA base = 'unknown' if version == 2: if tc == 29: SIL_SUP = common.bin2int(msgbin[39]) elif tc == 31: SIL_SUP = common.bin2int(msgbin[86]) if SIL_SUP == 0: base = "hour" elif SIL_SUP == 1: base = "sample" return PE_RCu, PE_VPL, base
243,112
Check if a message is likely to be BDS code 5,0 (Track and turn report) Args: msg (String): 28 bytes hexadecimal message string Returns: bool: True or False
def is50(msg): if allzeros(msg): return False d = hex2bin(data(msg)) # status bit 1, 12, 24, 35, 46 if wrongstatus(d, 1, 3, 11): return False if wrongstatus(d, 12, 13, 23): return False if wrongstatus(d, 24, 25, 34): return False if wrongstatus(d, 35, 36, 45): return False if wrongstatus(d, 46, 47, 56): return False roll = roll50(msg) if (roll is not None) and abs(roll) > 60: return False gs = gs50(msg) if gs is not None and gs > 600: return False tas = tas50(msg) if tas is not None and tas > 500: return False if (gs is not None) and (tas is not None) and (abs(tas - gs) > 200): return False return True
243,113
Roll angle, BDS 5,0 message Args: msg (String): 28 bytes hexadecimal message (BDS50) string Returns: float: angle in degrees, negative->left wing down, positive->right wing down
def roll50(msg): d = hex2bin(data(msg)) if d[0] == '0': return None sign = int(d[1]) # 1 -> left wing down value = bin2int(d[2:11]) if sign: value = value - 512 angle = value * 45.0 / 256.0 # degree return round(angle, 1)
243,114
True track angle, BDS 5,0 message Args: msg (String): 28 bytes hexadecimal message (BDS50) string Returns: float: angle in degrees to true north (from 0 to 360)
def trk50(msg): d = hex2bin(data(msg)) if d[11] == '0': return None sign = int(d[12]) # 1 -> west value = bin2int(d[13:23]) if sign: value = value - 1024 trk = value * 90.0 / 512.0 # convert from [-180, 180] to [0, 360] if trk < 0: trk = 360 + trk return round(trk, 3)
243,115
Ground speed, BDS 5,0 message Args: msg (String): 28 bytes hexadecimal message (BDS50) string Returns: int: ground speed in knots
def gs50(msg): d = hex2bin(data(msg)) if d[23] == '0': return None spd = bin2int(d[24:34]) * 2 # kts return spd
243,116
Aircraft true airspeed, BDS 5,0 message Args: msg (String): 28 bytes hexadecimal message (BDS50) string Returns: int: true airspeed in knots
def tas50(msg): d = hex2bin(data(msg)) if d[45] == '0': return None tas = bin2int(d[46:56]) * 2 # kts return tas
243,117
Check if a message is likely to be BDS code 5,3 (Air-referenced state vector) Args: msg (String): 28 bytes hexadecimal message string Returns: bool: True or False
def is53(msg): if allzeros(msg): return False d = hex2bin(data(msg)) # status bit 1, 13, 24, 34, 47 if wrongstatus(d, 1, 3, 12): return False if wrongstatus(d, 13, 14, 23): return False if wrongstatus(d, 24, 25, 33): return False if wrongstatus(d, 34, 35, 46): return False if wrongstatus(d, 47, 49, 56): return False ias = ias53(msg) if ias is not None and ias > 500: return False mach = mach53(msg) if mach is not None and mach > 1: return False tas = tas53(msg) if tas is not None and tas > 500: return False vr = vr53(msg) if vr is not None and abs(vr) > 8000: return False return True
243,118
Indicated airspeed, DBS 5,3 message Args: msg (String): 28 bytes hexadecimal message Returns: int: indicated arispeed in knots
def ias53(msg): d = hex2bin(data(msg)) if d[12] == '0': return None ias = bin2int(d[13:23]) # knots return ias
243,119
MACH number, DBS 5,3 message Args: msg (String): 28 bytes hexadecimal message Returns: float: MACH number
def mach53(msg): d = hex2bin(data(msg)) if d[23] == '0': return None mach = bin2int(d[24:33]) * 0.008 return round(mach, 3)
243,120
Aircraft true airspeed, BDS 5,3 message Args: msg (String): 28 bytes hexadecimal message Returns: float: true airspeed in knots
def tas53(msg): d = hex2bin(data(msg)) if d[33] == '0': return None tas = bin2int(d[34:46]) * 0.5 # kts return round(tas, 1)
243,121
Check if a message is likely to be BDS code 1,0 Args: msg (String): 28 bytes hexadecimal message string Returns: bool: True or False
def is10(msg): if allzeros(msg): return False d = hex2bin(data(msg)) # first 8 bits must be 0x10 if d[0:8] != '00010000': return False # bit 10 to 14 are reserved if bin2int(d[9:14]) != 0: return False # overlay capabilty conflict if d[14] == '1' and bin2int(d[16:23]) < 5: return False if d[14] == '0' and bin2int(d[16:23]) > 4: return False return True
243,128
Check if a message is likely to be BDS code 1,7 Args: msg (String): 28 bytes hexadecimal message string Returns: bool: True or False
def is17(msg): if allzeros(msg): return False d = hex2bin(data(msg)) if bin2int(d[28:56]) != 0: return False caps = cap17(msg) # basic BDS codes for ADS-B shall be supported # assuming ADS-B out is installed (2017EU/2020US mandate) # if not set(['BDS05', 'BDS06', 'BDS08', 'BDS09', 'BDS20']).issubset(caps): # return False # at least you can respond who you are if 'BDS20' not in caps: return False return True
243,129
Extract capacities from BDS 1,7 message Args: msg (String): 28 bytes hexadecimal message string Returns: list: list of suport BDS codes
def cap17(msg): allbds = ['05', '06', '07', '08', '09', '0A', '20', '21', '40', '41', '42', '43', '44', '45', '48', '50', '51', '52', '53', '54', '55', '56', '5F', '60', 'NA', 'NA', 'E1', 'E2'] d = hex2bin(data(msg)) idx = [i for i, v in enumerate(d[:28]) if v=='1'] capacity = ['BDS'+allbds[i] for i in idx if allbds[i] is not 'NA'] return capacity
243,130
Calculate the speed, track (or heading), and vertical rate Args: msg (string): 28 bytes hexadecimal message string Returns: (int, float, int, string): speed (kt), ground track or heading (degree), rate of climb/descend (ft/min), and speed type ('GS' for ground speed, 'AS' for airspeed)
def airborne_velocity(msg): if common.typecode(msg) != 19: raise RuntimeError("%s: Not a airborne velocity message, expecting TC=19" % msg) mb = common.hex2bin(msg)[32:] subtype = common.bin2int(mb[5:8]) if common.bin2int(mb[14:24]) == 0 or common.bin2int(mb[25:35]) == 0: return None if subtype in (1, 2): v_ew_sign = -1 if mb[13]=='1' else 1 v_ew = common.bin2int(mb[14:24]) - 1 # east-west velocity v_ns_sign = -1 if mb[24]=='1' else 1 v_ns = common.bin2int(mb[25:35]) - 1 # north-south velocity v_we = v_ew_sign * v_ew v_sn = v_ns_sign * v_ns spd = math.sqrt(v_sn*v_sn + v_we*v_we) # unit in kts spd = int(spd) trk = math.atan2(v_we, v_sn) trk = math.degrees(trk) # convert to degrees trk = trk if trk >= 0 else trk + 360 # no negative val tag = 'GS' trk_or_hdg = round(trk, 2) else: if mb[13] == '0': hdg = None else: hdg = common.bin2int(mb[14:24]) / 1024.0 * 360.0 hdg = round(hdg, 2) trk_or_hdg = hdg spd = common.bin2int(mb[25:35]) spd = None if spd==0 else spd-1 if mb[24]=='0': tag = 'IAS' else: tag = 'TAS' vr_sign = -1 if mb[36]=='1' else 1 vr = common.bin2int(mb[37:46]) rocd = None if vr==0 else int(vr_sign*(vr-1)*64) return spd, trk_or_hdg, rocd, tag
243,134
Decode the differece between GNSS and barometric altitude Args: msg (string): 28 bytes hexadecimal message string, TC=19 Returns: int: Altitude difference in ft. Negative value indicates GNSS altitude below barometric altitude.
def altitude_diff(msg): tc = common.typecode(msg) if tc != 19: raise RuntimeError("%s: Not a airborne velocity message, expecting TC=19" % msg) msgbin = common.hex2bin(msg) sign = -1 if int(msgbin[80]) else 1 value = common.bin2int(msgbin[81:88]) if value == 0 or value == 127: return None else: return sign * (value - 1) * 25
243,135
Use reference ground speed and trk to determine BDS50 and DBS60. Args: msg (String): 28 bytes hexadecimal message string spd_ref (float): reference speed (ADS-B ground speed), kts trk_ref (float): reference track (ADS-B track angle), deg alt_ref (float): reference altitude (ADS-B altitude), ft Returns: String or None: BDS version, or possible versions, or None if nothing matches.
def is50or60(msg, spd_ref, trk_ref, alt_ref): def vxy(v, angle): vx = v * np.sin(np.radians(angle)) vy = v * np.cos(np.radians(angle)) return vx, vy if not (bds50.is50(msg) and bds60.is60(msg)): return None h50 = bds50.trk50(msg) v50 = bds50.gs50(msg) if h50 is None or v50 is None: return 'BDS50,BDS60' h60 = bds60.hdg60(msg) m60 = bds60.mach60(msg) i60 = bds60.ias60(msg) if h60 is None or (m60 is None and i60 is None): return 'BDS50,BDS60' m60 = np.nan if m60 is None else m60 i60 = np.nan if i60 is None else i60 XY5 = vxy(v50*aero.kts, h50) XY6m = vxy(aero.mach2tas(m60, alt_ref*aero.ft), h60) XY6i = vxy(aero.cas2tas(i60*aero.kts, alt_ref*aero.ft), h60) allbds = ['BDS50', 'BDS60', 'BDS60'] X = np.array([XY5, XY6m, XY6i]) Mu = np.array(vxy(spd_ref*aero.kts, trk_ref)) # compute Mahalanobis distance matrix # Cov = [[20**2, 0], [0, 20**2]] # mmatrix = np.sqrt(np.dot(np.dot(X-Mu, np.linalg.inv(Cov)), (X-Mu).T)) # dist = np.diag(mmatrix) # since the covariance matrix is identity matrix, # M-dist is same as eculidian distance try: dist = np.linalg.norm(X-Mu, axis=1) BDS = allbds[np.nanargmin(dist)] except ValueError: return 'BDS50,BDS60' return BDS
243,136
Estimate the most likely BDS code of an message. Args: msg (String): 28 bytes hexadecimal message string mrar (bool): Also infer MRAR (BDS 44) and MHR (BDS 45). Defaults to False. Returns: String or None: BDS version, or possible versions, or None if nothing matches.
def infer(msg, mrar=False): df = common.df(msg) if common.allzeros(msg): return 'EMPTY' # For ADS-B / Mode-S extended squitter if df == 17: tc = common.typecode(msg) if 1 <= tc <= 4: return 'BDS08' # indentification and category if 5 <= tc <= 8: return 'BDS06' # surface movement if 9 <= tc <= 18: return 'BDS05' # airborne position, baro-alt if tc == 19: return 'BDS09' # airborne velocity if 20 <= tc <= 22: return 'BDS05' # airborne position, gnss-alt if tc == 28: return 'BDS61' # aircraft status if tc == 29: return 'BDS62' # target state and status if tc == 31: return 'BDS65' # operational status # For Comm-B replies IS10 = bds10.is10(msg) IS17 = bds17.is17(msg) IS20 = bds20.is20(msg) IS30 = bds30.is30(msg) IS40 = bds40.is40(msg) IS50 = bds50.is50(msg) IS60 = bds60.is60(msg) IS44 = bds44.is44(msg) IS45 = bds45.is45(msg) if mrar: allbds = np.array(["BDS10", "BDS17", "BDS20", "BDS30", "BDS40", "BDS44", "BDS45", "BDS50", "BDS60"]) mask = [IS10, IS17, IS20, IS30, IS40, IS44, IS45, IS50, IS60] else: allbds = np.array(["BDS10", "BDS17", "BDS20", "BDS30", "BDS40", "BDS50", "BDS60"]) mask = [IS10, IS17, IS20, IS30, IS40, IS50, IS60] bds = ','.join(sorted(allbds[mask])) if len(bds) == 0: return None else: return bds
243,137
Check if a message is likely to be BDS code 4,0 Args: msg (String): 28 bytes hexadecimal message string Returns: bool: True or False
def is40(msg): if allzeros(msg): return False d = hex2bin(data(msg)) # status bit 1, 14, and 27 if wrongstatus(d, 1, 2, 13): return False if wrongstatus(d, 14, 15, 26): return False if wrongstatus(d, 27, 28, 39): return False if wrongstatus(d, 48, 49, 51): return False if wrongstatus(d, 54, 55, 56): return False # bits 40-47 and 52-53 shall all be zero if bin2int(d[39:47]) != 0: return False if bin2int(d[51:53]) != 0: return False return True
243,138
Selected altitude, MCP/FCU Args: msg (String): 28 bytes hexadecimal message (BDS40) string Returns: int: altitude in feet
def alt40mcp(msg): d = hex2bin(data(msg)) if d[0] == '0': return None alt = bin2int(d[1:13]) * 16 # ft return alt
243,139
Selected altitude, FMS Args: msg (String): 28 bytes hexadecimal message (BDS40) string Returns: int: altitude in feet
def alt40fms(msg): d = hex2bin(data(msg)) if d[13] == '0': return None alt = bin2int(d[14:26]) * 16 # ft return alt
243,140
Barometric pressure setting Args: msg (String): 28 bytes hexadecimal message (BDS40) string Returns: float: pressure in millibar
def p40baro(msg): d = hex2bin(data(msg)) if d[26] == '0': return None p = bin2int(d[27:39]) * 0.1 + 800 # millibar return p
243,141
Check if a message is likely to be BDS code 4,4. Meteorological routine air report Args: msg (String): 28 bytes hexadecimal message string Returns: bool: True or False
def is44(msg): if allzeros(msg): return False d = hex2bin(data(msg)) # status bit 5, 35, 47, 50 if wrongstatus(d, 5, 6, 23): return False if wrongstatus(d, 35, 36, 46): return False if wrongstatus(d, 47, 48, 49): return False if wrongstatus(d, 50, 51, 56): return False # Bits 1-4 indicate source, values > 4 reserved and should not occur if bin2int(d[0:4]) > 4: return False vw = wind44(msg) if vw is not None and vw[0] > 250: return False temp, temp2 = temp44(msg) if min(temp, temp2) > 60 or max(temp, temp2) < -80: return False return True
243,142
Wind speed and direction. Args: msg (String): 28 bytes hexadecimal message string Returns: (int, float): speed (kt), direction (degree)
def wind44(msg): d = hex2bin(data(msg)) status = int(d[4]) if not status: return None speed = bin2int(d[5:14]) # knots direction = bin2int(d[14:23]) * 180.0 / 256.0 # degree return round(speed, 0), round(direction, 1)
243,143
Static air temperature. Args: msg (String): 28 bytes hexadecimal message string Returns: float, float: temperature and alternative temperature in Celsius degree. Note: Two values returns due to what seems to be an inconsistancy error in ICAO 9871 (2008) Appendix A-67.
def temp44(msg): d = hex2bin(data(msg)) sign = int(d[23]) value = bin2int(d[24:34]) if sign: value = value - 1024 temp = value * 0.25 # celsius temp = round(temp, 2) temp_alternative = value * 0.125 # celsius temp_alternative = round(temp, 3) return temp, temp_alternative
243,144
Static pressure. Args: msg (String): 28 bytes hexadecimal message string Returns: int: static pressure in hPa
def p44(msg): d = hex2bin(data(msg)) if d[34] == '0': return None p = bin2int(d[35:46]) # hPa return p
243,145
humidity Args: msg (String): 28 bytes hexadecimal message string Returns: float: percentage of humidity, [0 - 100] %
def hum44(msg): d = hex2bin(data(msg)) if d[49] == '0': return None hm = bin2int(d[50:56]) * 100.0 / 64 # % return round(hm, 1)
243,146
Turblence. Args: msg (String): 28 bytes hexadecimal message string Returns: int: turbulence level. 0=NIL, 1=Light, 2=Moderate, 3=Severe
def turb44(msg): d = hex2bin(data(msg)) if d[46] == '0': return None turb = bin2int(d[47:49]) return turb
243,147
Decode surface velocity from from a surface position message Args: msg (string): 28 bytes hexadecimal message string Returns: (int, float, int, string): speed (kt), ground track (degree), rate of climb/descend (ft/min), and speed type ('GS' for ground speed, 'AS' for airspeed)
def surface_velocity(msg): if common.typecode(msg) < 5 or common.typecode(msg) > 8: raise RuntimeError("%s: Not a surface message, expecting 5<TC<8" % msg) mb = common.hex2bin(msg)[32:] # ground track trk_status = int(mb[12]) if trk_status == 1: trk = common.bin2int(mb[13:20]) * 360.0 / 128.0 trk = round(trk, 1) else: trk = None # ground movment / speed mov = common.bin2int(mb[5:12]) if mov == 0 or mov > 124: spd = None elif mov == 1: spd = 0 elif mov == 124: spd = 175 else: movs = [2, 9, 13, 39, 94, 109, 124] kts = [0.125, 1, 2, 15, 70, 100, 175] i = next(m[0] for m in enumerate(movs) if m[1] > mov) step = (kts[i] - kts[i-1]) * 1.0 / (movs[i]-movs[i-1]) spd = kts[i-1] + (mov-movs[i-1]) * step spd = round(spd, 2) return spd, trk, 0, 'GS'
243,149
Check if a message is likely to be BDS code 2,0 Args: msg (String): 28 bytes hexadecimal message string Returns: bool: True or False
def is20(msg): if allzeros(msg): return False d = hex2bin(data(msg)) if d[0:8] != '00100000': return False cs = cs20(msg) if '#' in cs: return False return True
243,150
Aircraft callsign Args: msg (String): 28 bytes hexadecimal message (BDS40) string Returns: string: callsign, max. 8 chars
def cs20(msg): chars = '#ABCDEFGHIJKLMNOPQRSTUVWXYZ#####_###############0123456789######' d = hex2bin(data(msg)) cs = '' cs += chars[bin2int(d[8:14])] cs += chars[bin2int(d[14:20])] cs += chars[bin2int(d[20:26])] cs += chars[bin2int(d[26:32])] cs += chars[bin2int(d[32:38])] cs += chars[bin2int(d[38:44])] cs += chars[bin2int(d[44:50])] cs += chars[bin2int(d[50:56])] return cs
243,151
Check if a message is likely to be BDS code 6,0 Args: msg (String): 28 bytes hexadecimal message string Returns: bool: True or False
def is60(msg): if allzeros(msg): return False d = hex2bin(data(msg)) # status bit 1, 13, 24, 35, 46 if wrongstatus(d, 1, 2, 12): return False if wrongstatus(d, 13, 14, 23): return False if wrongstatus(d, 24, 25, 34): return False if wrongstatus(d, 35, 36, 45): return False if wrongstatus(d, 46, 47, 56): return False ias = ias60(msg) if ias is not None and ias > 500: return False mach = mach60(msg) if mach is not None and mach > 1: return False vr_baro = vr60baro(msg) if vr_baro is not None and abs(vr_baro) > 6000: return False vr_ins = vr60ins(msg) if vr_ins is not None and abs(vr_ins) > 6000: return False return True
243,152
Megnetic heading of aircraft Args: msg (String): 28 bytes hexadecimal message (BDS60) string Returns: float: heading in degrees to megnetic north (from 0 to 360)
def hdg60(msg): d = hex2bin(data(msg)) if d[0] == '0': return None sign = int(d[1]) # 1 -> west value = bin2int(d[2:12]) if sign: value = value - 1024 hdg = value * 90 / 512.0 # degree # convert from [-180, 180] to [0, 360] if hdg < 0: hdg = 360 + hdg return round(hdg, 3)
243,153
Indicated airspeed Args: msg (String): 28 bytes hexadecimal message (BDS60) string Returns: int: indicated airspeed in knots
def ias60(msg): d = hex2bin(data(msg)) if d[12] == '0': return None ias = bin2int(d[13:23]) # kts return ias
243,154
Aircraft MACH number Args: msg (String): 28 bytes hexadecimal message (BDS60) string Returns: float: MACH number
def mach60(msg): d = hex2bin(data(msg)) if d[23] == '0': return None mach = bin2int(d[24:34]) * 2.048 / 512.0 return round(mach, 3)
243,155
Vertical rate from barometric measurement, this value may be very noisy. Args: msg (String): 28 bytes hexadecimal message (BDS60) string Returns: int: vertical rate in feet/minutes
def vr60baro(msg): d = hex2bin(data(msg)) if d[34] == '0': return None sign = int(d[35]) # 1 -> negative value, two's complement value = bin2int(d[36:45]) if value == 0 or value == 511: # all zeros or all ones return 0 value = value - 512 if sign else value roc = value * 32 # feet/min return roc
243,156
Check if a message is likely to be BDS code 4,5. Meteorological hazard report Args: msg (String): 28 bytes hexadecimal message string Returns: bool: True or False
def is45(msg): if allzeros(msg): return False d = hex2bin(data(msg)) # status bit 1, 4, 7, 10, 13, 16, 27, 39 if wrongstatus(d, 1, 2, 3): return False if wrongstatus(d, 4, 5, 6): return False if wrongstatus(d, 7, 8, 9): return False if wrongstatus(d, 10, 11, 12): return False if wrongstatus(d, 13, 14, 15): return False if wrongstatus(d, 16, 17, 26): return False if wrongstatus(d, 27, 28, 38): return False if wrongstatus(d, 39, 40, 51): return False # reserved if bin2int(d[51:56]) != 0: return False temp = temp45(msg) if temp: if temp > 60 or temp < -80: return False return True
243,157
Turbulence. Args: msg (String): 28 bytes hexadecimal message string Returns: int: Turbulence level. 0=NIL, 1=Light, 2=Moderate, 3=Severe
def turb45(msg): d = hex2bin(data(msg)) if d[0] == '0': return None turb = bin2int(d[1:3]) return turb
243,158
Wind shear. Args: msg (String): 28 bytes hexadecimal message string Returns: int: Wind shear level. 0=NIL, 1=Light, 2=Moderate, 3=Severe
def ws45(msg): d = hex2bin(data(msg)) if d[3] == '0': return None ws = bin2int(d[4:6]) return ws
243,159
Microburst. Args: msg (String): 28 bytes hexadecimal message string Returns: int: Microburst level. 0=NIL, 1=Light, 2=Moderate, 3=Severe
def mb45(msg): d = hex2bin(data(msg)) if d[6] == '0': return None mb = bin2int(d[7:9]) return mb
243,160
Icing. Args: msg (String): 28 bytes hexadecimal message string Returns: int: Icing level. 0=NIL, 1=Light, 2=Moderate, 3=Severe
def ic45(msg): d = hex2bin(data(msg)) if d[9] == '0': return None ic = bin2int(d[10:12]) return ic
243,161
Wake vortex. Args: msg (String): 28 bytes hexadecimal message string Returns: int: Wake vortex level. 0=NIL, 1=Light, 2=Moderate, 3=Severe
def wv45(msg): d = hex2bin(data(msg)) if d[12] == '0': return None ws = bin2int(d[13:15]) return ws
243,162
Static air temperature. Args: msg (String): 28 bytes hexadecimal message string Returns: float: tmeperature in Celsius degree
def temp45(msg): d = hex2bin(data(msg)) sign = int(d[16]) value = bin2int(d[17:26]) if sign: value = value - 512 temp = value * 0.25 # celsius temp = round(temp, 1) return temp
243,163
Average static pressure. Args: msg (String): 28 bytes hexadecimal message string Returns: int: static pressure in hPa
def p45(msg): d = hex2bin(data(msg)) if d[26] == '0': return None p = bin2int(d[27:38]) # hPa return p
243,164
Radio height. Args: msg (String): 28 bytes hexadecimal message string Returns: int: radio height in ft
def rh45(msg): d = hex2bin(data(msg)) if d[38] == '0': return None rh = bin2int(d[39:51]) * 16 return rh
243,165
Get the list of Movie genres. Args: language: (optional) ISO 639-1 code. Returns: A dict respresentation of the JSON returned from the API.
def movie_list(self, **kwargs): path = self._get_path('movie_list') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
243,764
Get the list of TV genres. Args: language: (optional) ISO 639-1 code. Returns: A dict respresentation of the JSON returned from the API.
def tv_list(self, **kwargs): path = self._get_path('tv_list') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
243,765
Get the basic movie information for a specific movie id. Args: language: (optional) ISO 639-1 code. append_to_response: (optional) Comma separated, any movie method. Returns: A dict representation of the JSON returned from the API.
def info(self, **kwargs): path = self._get_id_path('info') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
243,768
Get the alternative titles for a specific movie id. Args: country: (optional) ISO 3166-1 code. append_to_response: (optional) Comma separated, any movie method. Returns: A dict representation of the JSON returned from the API.
def alternative_titles(self, **kwargs): path = self._get_id_path('alternative_titles') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
243,769
Get the cast and crew information for a specific movie id. Args: append_to_response: (optional) Comma separated, any movie method. Returns: A dict representation of the JSON returned from the API.
def credits(self, **kwargs): path = self._get_id_path('credits') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
243,770
Get the external ids for a specific movie id. Args: language: (optional) ISO 639-1 code. append_to_response: (optional) Comma separated, any movie method. Returns: A dict representation of the JSON returned from the API.
def external_ids(self, **kwargs): path = self._get_id_path('external_ids') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
243,771
Get the images (posters and backdrops) for a specific movie id. Args: language: (optional) ISO 639-1 code. append_to_response: (optional) Comma separated, any movie method. include_image_language: (optional) Comma separated, a valid ISO 69-1. Returns: A dict representation of the JSON returned from the API.
def images(self, **kwargs): path = self._get_id_path('images') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
243,772
Get a list of recommended movies for a movie. Args: language: (optional) ISO 639-1 code. page: (optional) Minimum value of 1. Expected value is an integer. Returns: A dict representation of the JSON returned from the API.
def recommendations(self, **kwargs): path = self._get_id_path('recommendations') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
243,774
Get the release dates and certification for a specific movie id. Args: append_to_response: (optional) Comma separated, any movie method. Returns: A dict representation of the JSON returned from the API.
def release_dates(self, **kwargs): path = self._get_id_path('release_dates') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
243,775
Get the release date and certification information by country for a specific movie id. Args: append_to_response: (optional) Comma separated, any movie method. Returns: A dict representation of the JSON returned from the API.
def releases(self, **kwargs): path = self._get_id_path('releases') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
243,776
Get the videos (trailers, teasers, clips, etc...) for a specific movie id. Args: append_to_response: (optional) Comma separated, any movie method. Returns: A dict representation of the JSON returned from the API.
def videos(self, **kwargs): path = self._get_id_path('videos') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
243,777
Get the translations for a specific movie id. Args: append_to_response: (optional) Comma separated, any movie method. Returns: A dict representation of the JSON returned from the API.
def translations(self, **kwargs): path = self._get_id_path('translations') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
243,778
Get the similar movies for a specific movie id. Args: page: (optional) Minimum value of 1. Expected value is an integer. language: (optional) ISO 639-1 code. append_to_response: (optional) Comma separated, any movie method. Returns: A dict representation of the JSON returned from the API.
def similar_movies(self, **kwargs): path = self._get_id_path('similar_movies') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
243,779
Get the reviews for a particular movie id. Args: page: (optional) Minimum value of 1. Expected value is an integer. language: (optional) ISO 639-1 code. append_to_response: (optional) Comma separated, any movie method. Returns: A dict representation of the JSON returned from the API.
def reviews(self, **kwargs): path = self._get_id_path('reviews') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
243,780
Get the list of upcoming movies. This list refreshes every day. The maximum number of items this list will include is 100. Args: page: (optional) Minimum value of 1. Expected value is an integer. language: (optional) ISO 639-1 code. Returns: A dict representation of the JSON returned from the API.
def upcoming(self, **kwargs): path = self._get_path('upcoming') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
243,783
Get the list of movies playing in theatres. This list refreshes every day. The maximum number of items this list will include is 100. Args: page: (optional) Minimum value of 1. Expected value is an integer. language: (optional) ISO 639-1 code. Returns: A dict representation of the JSON returned from the API.
def now_playing(self, **kwargs): path = self._get_path('now_playing') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
243,784
Get the list of popular movies on The Movie Database. This list refreshes every day. Args: page: (optional) Minimum value of 1. Expected value is an integer. language: (optional) ISO 639-1 code. Returns: A dict representation of the JSON returned from the API.
def popular(self, **kwargs): path = self._get_path('popular') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
243,785
Get the list of top rated movies. By default, this list will only include movies that have 10 or more votes. This list refreshes every day. Args: page: (optional) Minimum value of 1. Expected value is an integer. language: (optional) ISO 639-1 code. Returns: A dict representation of the JSON returned from the API.
def top_rated(self, **kwargs): path = self._get_path('top_rated') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
243,786
This method lets users get the status of whether or not the movie has been rated or added to their favourite or watch lists. A valid session id is required. Args: session_id: see Authentication. Returns: A dict representation of the JSON returned from the API.
def account_states(self, **kwargs): path = self._get_id_path('account_states') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
243,787
This method lets users rate a movie. A valid session id or guest session id is required. Args: session_id: see Authentication. guest_session_id: see Authentication. value: Rating value. Returns: A dict representation of the JSON returned from the API.
def rating(self, **kwargs): path = self._get_id_path('rating') payload = { 'value': kwargs.pop('value', None), } response = self._POST(path, kwargs, payload) self._set_attrs_to_values(response) return response
243,788
Get the movie credits for a specific person id. Args: language: (optional) ISO 639-1 code. append_to_response: (optional) Comma separated, any person method. Returns: A dict respresentation of the JSON returned from the API.
def movie_credits(self, **kwargs): path = self._get_id_path('movie_credits') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
243,794
Get the TV credits for a specific person id. Args: language: (optional) ISO 639-1 code. append_to_response: (optional) Comma separated, any person method. Returns: A dict respresentation of the JSON returned from the API.
def tv_credits(self, **kwargs): path = self._get_id_path('tv_credits') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
243,795
Get the list of movies on an account watchlist. Args: page: (optional) Minimum 1, maximum 1000. sort_by: (optional) 'created_at.asc' | 'created_at.desc' language: (optional) ISO 639-1 code. Returns: A dict respresentation of the JSON returned from the API.
def watchlist_movies(self, **kwargs): path = self._get_id_path('watchlist_movies') kwargs.update({'session_id': self.session_id}) response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
243,804
Authenticate a user with a TMDb username and password. The user must have a verified email address and be registered on TMDb. Args: request_token: The token you generated for the user to approve. username: The user's username on TMDb. password: The user's password on TMDb. Returns: A dict respresentation of the JSON returned from the API.
def token_validate_with_login(self, **kwargs): path = self._get_path('token_validate_with_login') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
243,806
Generate a session id for user based authentication. A session id is required in order to use any of the write methods. Args: request_token: The token you generated for the user to approve. The token needs to be approved before being used here. Returns: A dict respresentation of the JSON returned from the API.
def session_new(self, **kwargs): path = self._get_path('session_new') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
243,807