<commit_before>"""
    Just a collection of helper functions to 
    do common tasks.
"""
# pylint: disable=W0312

import requests, time, json
from urllib.parse import quote_plus

def dictify_device_meta(device_object):
    try:
        if isinstance(device_object['description']['meta'], str):
            device_object['description']['meta'] =\
                json.loads(device_object['description']['meta'])
    except ValueError as err:
        print("dictify: {0}".format(device_object['description']['meta']))
    return device_object

def get_map_url_and_timezone(address):
    """
        This function takes an address as input
        and returns a tuple of (timezone, google_map_url).
    """
    GOOGLE_API_URL='https://maps.googleapis.com/maps/api'

    linkurl = '{0}/geocode/json?address={1}&sensor=false'.format(
            GOOGLE_API_URL,quote_plus(address))
    linkblob = requests.get(linkurl).json()
    latlong = linkblob['results'][0]['geometry']['location']
    map_url = 'https://www.google.com/maps?q={0},{1}'.format(
                                    latlong['lat'], latlong['lng'])
    print('Link to map of address: {0}'.format(map_url))
    
    tzurl = '{0}/timezone/json?location={1},{2}&timestamp={3}'.format(
            GOOGLE_API_URL,latlong['lat'], latlong['lng'], int(time.time()))
    tzblob = requests.get(tzurl).json()
    tz = tzblob['timeZoneId']
    print("Timezone of address {0}".format(tz))
    return (tz, map_url)

<commit_msg>Added stringify_device_meta to provide an 'undo' of dictify. Added docstrings.<commit_after>"""
    Just a collection of helper functions to 
    do common tasks.
"""
# pylint: disable=W0312

import requests, time, json
from urllib.parse import quote_plus

def dictify_device_meta(device_object):
    """ Input: Portals device object.
        Output: The same device object with the device meta
                converted to a python dictionary. """
    try:
        if isinstance(device_object['info']['description']['meta'], str):
            device_object['info']['description']['meta'] =\
                json.loads(device_object['info']['description']['meta'])
    except ValueError as err:
        print("dictify: {0}".format(err))
    return device_object

def stringify_device_meta(device_object):
    """ Input: Portals device object.
        Output: The same device object with the device meta
                converted to a python string. """
    try:
        if isinstance(device_object['info']['description']['meta'], dict):
            device_object['info']['description']['meta'] =\
                json.dumps(device_object['info']['description']['meta'])
    except ValueError as err:
        print("stringify: {0}".format(err))
    return device_object

def get_map_url_and_timezone(address):
    """
        This function takes an address as input
        and returns a tuple of (timezone, google_map_url).
    """
    GOOGLE_API_URL='https://maps.googleapis.com/maps/api'

    linkurl = '{0}/geocode/json?address={1}&sensor=false'.format(
            GOOGLE_API_URL,quote_plus(address))
    linkblob = requests.get(linkurl).json()
    latlong = linkblob['results'][0]['geometry']['location']
    map_url = 'https://www.google.com/maps?q={0},{1}'.format(
                                    latlong['lat'], latlong['lng'])
    print('Link to map of address: {0}'.format(map_url))
    
    tzurl = '{0}/timezone/json?location={1},{2}&timestamp={3}'.format(
            GOOGLE_API_URL,latlong['lat'], latlong['lng'], int(time.time()))
    tzblob = requests.get(tzurl).json()
    tz = tzblob['timeZoneId']
    print("Timezone of address {0}".format(tz))
    return (tz, map_url)


{'fraction_non_alphanumeric': 0.15191941192485706, 'fraction_numerical': 0.008984481350394773, 'mean_word_length': 3.297076023391813, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2607824', 'n_tokens_mistral': 1112, 'n_tokens_neox': 1085, 'n_words': 235}