jp_mobile_carriers module¶
-
jp_mobile_carriers.docomo_has_messages(scrape)[source]¶ Checks if Docomo has messages for a number being inquired in its own system, that is, the given scrape contains urls for the stored messages. Args:
scrape: the scraped content from Docomo.- Returns:
- True if Docomo has messaes, and False otherwise.
-
jp_mobile_carriers.extract_redirect_url(scrape)[source]¶ Tries to extract a further redirect URL for the correct mobile carrier page from the given page scraped from Docomo. If finds a further redirect url to other carrier’s page, returns that final destination url, otherwise returns None. Args:
scrape: the scraped content from the url.- Returns:
- url for further redirect to an appropriate mobile carrier’s message board page if it’s found, otherwise None.
-
jp_mobile_carriers.get_docomo_post_data(number, hidden_param)[source]¶ Returns a mapping for POST data to Docomo’s url to inquire for messages for the given number. Args:
number: a normalized mobile number.- Returns:
- a mapping for the POST data.
-
jp_mobile_carriers.get_phone_number(string)[source]¶ Normalize the given string, which may be a phone number, and returns a normalized phone number if the string is a phone number, or None otherwise. Gets rid of separator characters, converts unicode characters to ascii chars, and if the phone number contains the country code for Japan (81), strips of the code and prepend ‘0’. Args:
string: unicode string to normalize.- Returns:
- A normalized phone number if the input string is phone number, or None otherwise.
-
jp_mobile_carriers.handle_phone_number(handler, query)[source]¶ Handles a phone number query. If the query is a mobile phone number, looks up the number for registered messages in the mobile carriers-provided message board services and redirects to the results page. If the query is a non-mobile phone number, shows a 171 suggestion. Args:
handler: a request handler for this request. query: a query string to the Person Finder query page.- Returns:
- True if the query string is a phone number and has been properly handled, and False otherwise.
-
jp_mobile_carriers.is_mobile_number(string)[source]¶ Tests the given string matches the pattern for the Japanese mobile phone number. Args:
string: unicode string that is stripped of phone number separators such as ‘(‘, ‘)’, and ‘-‘ and converted into ascii numeric characters.- Returns:
- True if the string is a Jp mobile phone number, and False otherwise.
-
jp_mobile_carriers.look_up_number(number)[source]¶ Look up messages for the number, registered in the Japanese mobile carriers-provided emergency message board services. The five Japanese mobile carriers maintain separate message indices, but their systems can talk to one another when they don’t find messages for the given number in their own indices. This function first talks to Docomo’s system as a main entry point. Docomo returns urls of registered messages if it finds ones in its system. If it doesn’t, Docomo’s system talks to the other 4 carriers’ and returns an url for an appropriate carrier if messages are found. If no messages are found registered for the number, Docomo’s system simply indicates so. Args:
number: A mobile phone number.- Returns:
- A url for messages found registered to some carrier (including Docomo) or None if no are found.
- Throws:
- Exception when failed to scrape.