forked from daviddrysdale/python-phonenumbers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphonenumbers.geocoder.html
More file actions
130 lines (127 loc) · 11.9 KB
/
Copy pathphonenumbers.geocoder.html
File metadata and controls
130 lines (127 loc) · 11.9 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module phonenumbers.geocoder</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="phonenumbers.html"><font color="#ffffff">phonenumbers</font></a>.geocoder</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="https://github.com/daviddrysdale/python-phonenumbers/blob/dev/python/phonenumbers/geocoder.py">phonenumbers/geocoder.py</a></font></td></tr></table>
<p><tt>Phone number geocoding functionality<br>
<br>
>>> import phonenumbers<br>
>>> from phonenumbers.geocoder import description_for_number<br>
>>> from phonenumbers.util import u<br>
>>> gb_number = phonenumbers.parse("+442083612345", "GB")<br>
>>> de_number = phonenumbers.parse("0891234567", "DE")<br>
>>> ch_number = phonenumbers.parse("0431234567", "CH")<br>
>>> str(<a href="#-description_for_number">description_for_number</a>(gb_number, "en"))<br>
'London'<br>
>>> str(<a href="#-description_for_number">description_for_number</a>(gb_number, "fr")) # fall back to English<br>
'London'<br>
>>> str(<a href="#-description_for_number">description_for_number</a>(gb_number, "en", region="GB"))<br>
'London'<br>
>>> str(<a href="#-description_for_number">description_for_number</a>(gb_number, "en", region="US")) # fall back to country<br>
'United Kingdom'<br>
>>> str(<a href="#-description_for_number">description_for_number</a>(de_number, "en"))<br>
'Munich'<br>
>>> u('München') == <a href="#-description_for_number">description_for_number</a>(de_number, "de")<br>
True<br>
>>> u('Zürich') == <a href="#-description_for_number">description_for_number</a>(ch_number, "de")<br>
True<br>
>>> str(<a href="#-description_for_number">description_for_number</a>(ch_number, "en"))<br>
'Zurich'<br>
>>> str(<a href="#-description_for_number">description_for_number</a>(ch_number, "fr"))<br>
'Zurich'<br>
>>> str(<a href="#-description_for_number">description_for_number</a>(ch_number, "it"))<br>
'Zurigo'</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td>
<td width="100%"><dl><dt><a name="-country_name_for_number"><strong>country_name_for_number</strong></a>(numobj, lang, script=None, region=None)</dt><dd><tt>Returns the customary display name in the given language for the given<br>
territory the given PhoneNumber object is from. If it could be from many<br>
territories, nothing is returned.<br>
<br>
Arguments:<br>
numobj -- The PhoneNumber object for which we want to get a text description.<br>
lang -- A 2-letter lowercase ISO 639-1 language code for the language in<br>
which the description should be returned (e.g. "en")<br>
script -- A 4-letter titlecase (first letter uppercase, rest lowercase)<br>
ISO script code as defined in ISO 15924, separated by an<br>
underscore (e.g. "Hant")<br>
region -- A 2-letter uppercase ISO 3166-1 country code (e.g. "GB")<br>
<br>
The script and region parameters are currently ignored.<br>
<br>
Returns a text description in the given language code, for the given phone<br>
number's region, or an empty string if no description is available.</tt></dd></dl>
<dl><dt><a name="-description_for_number"><strong>description_for_number</strong></a>(numobj, lang, script=None, region=None)</dt><dd><tt>Return a text description of a PhoneNumber object for the given language.<br>
<br>
The description might consist of the name of the country where the phone<br>
number is from and/or the name of the geographical area the phone number<br>
is from. This function explicitly checks the validity of the number passed in<br>
<br>
Arguments:<br>
numobj -- The PhoneNumber object for which we want to get a text description.<br>
lang -- A 2-letter lowercase ISO 639-1 language code for the language in<br>
which the description should be returned (e.g. "en")<br>
script -- A 4-letter titlecase (first letter uppercase, rest lowercase)<br>
ISO script code as defined in ISO 15924, separated by an<br>
underscore (e.g. "Hant")<br>
region -- The region code for a given user. This region will be omitted<br>
from the description if the phone number comes from this<br>
region. It should be a two-letter upper-case CLDR region<br>
code.<br>
<br>
Returns a text description in the given language code, for the given phone<br>
number, or an empty string if no description is available.</tt></dd></dl>
<dl><dt><a name="-description_for_valid_number"><strong>description_for_valid_number</strong></a>(numobj, lang, script=None, region=None)</dt><dd><tt>Return a text description of a PhoneNumber object, in the language<br>
provided.<br>
<br>
The description might consist of the name of the country where the phone<br>
number is from and/or the name of the geographical area the phone number<br>
is from if more detailed information is available.<br>
<br>
If the phone number is from the same region as the user, only a<br>
lower-level description will be returned, if one exists. Otherwise, the<br>
phone number's region will be returned, with optionally some more detailed<br>
information.<br>
<br>
For example, for a user from the region "US" (United States), we would<br>
show "Mountain View, CA" for a particular number, omitting the United<br>
States from the description. For a user from the United Kingdom (region<br>
"GB"), for the same number we may show "Mountain View, CA, United States"<br>
or even just "United States".<br>
<br>
This function assumes the validity of the number passed in has already<br>
been checked, and that the number is suitable for geocoding. We consider<br>
fixed-line and mobile numbers possible candidates for geocoding.<br>
<br>
Arguments:<br>
numobj -- A valid PhoneNumber object for which we want to get a text<br>
description.<br>
lang -- A 2-letter lowercase ISO 639-1 language code for the language in<br>
which the description should be returned (e.g. "en")<br>
script -- A 4-letter titlecase (first letter uppercase, rest lowercase)<br>
ISO script code as defined in ISO 15924, separated by an<br>
underscore (e.g. "Hant")<br>
region -- The region code for a given user. This region will be omitted<br>
from the description if the phone number comes from this<br>
region. It should be a two-letter upper-case CLDR region<br>
code.<br>
<br>
Returns a text description in the given language code, for the given phone<br>
number, or an empty string if the number could come from multiple countries,<br>
or the country code is in fact invalid.</tt></dd></dl>
</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td>
<td width="100%"><strong>__all__</strong> = ['country_name_for_number', 'description_for_valid_number', 'description_for_number']</td></tr></table>
</body></html>