def get_labs(format):
    """Gets data from all labs from makeinitaly.foundation."""

    labs = []

    # Get the first page of data
    wiki = MediaWiki(makeinitaly__foundation_api_url)
    wiki_response = wiki.call(
        {'action': 'query',
         'list': 'categorymembers',
         'cmtitle': 'Category:Italian_FabLabs',
         'cmlimit': '500'})
    if "query-continue" in wiki_response:
        nextpage = wiki_response[
            "query-continue"]["categorymembers"]["cmcontinue"]

    urls = []
    for i in wiki_response["query"]["categorymembers"]:
        urls.append(i["title"].replace(" ", "_"))

    # Load all the Labs in the first page
    for i in urls:
        current_lab = get_single_lab(i)
        labs.append(current_lab)

    # Load all the Labs from the other pages
    while "query-continue" in wiki_response:
        wiki = MediaWiki(makeinitaly__foundation_api_url)
        wiki_response = wiki.call({'action': 'query',
                                   'list': 'categorymembers',
                                   'cmtitle': 'Category:Hackerspace',
                                   'cmlimit': '500',
                                   "cmcontinue": nextpage})

        urls = []
        for i in wiki_response["query"]["categorymembers"]:
            urls.append(i["title"].replace(" ", "_"))

        # Load all the Labs
        for i in urls:
            current_lab = get_single_lab(i, data_format)
            labs.append(current_lab)

        if "query-continue" in wiki_response:
            nextpage = wiki_response[
                "query-continue"]["categorymembers"]["cmcontinue"]
        else:
            break

    # Transform the list into a dictionary
    labs_dict = {}
    for j, k in enumerate(labs):
        labs_dict[j] = k.__dict__

    # Return a dictiornary / json
    if format.lower() == "dict" or format.lower() == "json":
        output = labs_dict
    # Return a geojson
    elif format.lower() == "geojson" or format.lower() == "geo":
        labs_list = []
        for l in labs_dict:
            single = labs_dict[l].__dict__
            single_lab = Feature(
                type="Feature",
                geometry=Point((single["latitude"], single["longitude"])),
                properties=single)
            labs_list.append(single_lab)
        output = dumps(FeatureCollection(labs_list))
    # Return a Pandas DataFrame
    elif format.lower() == "pandas" or format.lower() == "dataframe":
        output = {}
        for j in labs_dict:
            output[j] = labs_dict[j].__dict__
        # Transform the dict into a Pandas DataFrame
        output = pd.DataFrame.from_dict(output)
        output = output.transpose()
    # Return an object
    elif format.lower() == "object" or format.lower() == "obj":
        output = labs
    # Default: return an object
    else:
        output = labs
    # Return a proper json
    if format.lower() == "json":
        output = json.dumps(labs_dict)
    return output
def get_labs ( format ) : labs = [ ] wiki = MediaWiki ( makeinitaly__foundation_api_url ) wiki_response = wiki . call ( { 'action' : 'query' , 'list' : 'categorymembers' , 'cmtitle' : 'Category:Italian_FabLabs' , 'cmlimit' : '500' } ) if "query-continue" in wiki_response : nextpage = wiki_response [ "query-continue" ] [ "categorymembers" ] [ "cmcontinue" ] urls = [ ] for i in wiki_response [ "query" ] [ "categorymembers" ] : urls . append ( i [ "title" ] . replace ( " " , "_" ) ) for i in urls : current_lab = get_single_lab ( i ) labs . append ( current_lab ) while "query-continue" in wiki_response : wiki = MediaWiki ( makeinitaly__foundation_api_url ) wiki_response = wiki . call ( { 'action' : 'query' , 'list' : 'categorymembers' , 'cmtitle' : 'Category:Hackerspace' , 'cmlimit' : '500' , "cmcontinue" : nextpage } ) urls = [ ] for i in wiki_response [ "query" ] [ "categorymembers" ] : urls . append ( i [ "title" ] . replace ( " " , "_" ) ) for i in urls : current_lab = get_single_lab ( i , data_format ) labs . append ( current_lab ) if "query-continue" in wiki_response : nextpage = wiki_response [ "query-continue" ] [ "categorymembers" ] [ "cmcontinue" ] else : break labs_dict = { } for j , k in enumerate ( labs ) : labs_dict [ j ] = k . __dict__ if format . lower ( ) == "dict" or format . lower ( ) == "json" : output = labs_dict elif format . lower ( ) == "geojson" or format . lower ( ) == "geo" : labs_list = [ ] for l in labs_dict : single = labs_dict [ l ] . __dict__ single_lab = Feature ( type = "Feature" , geometry = Point ( ( single [ "latitude" ] , single [ "longitude" ] ) ) , properties = single ) labs_list . append ( single_lab ) output = dumps ( FeatureCollection ( labs_list ) ) elif format . lower ( ) == "pandas" or format . lower ( ) == "dataframe" : output = { } for j in labs_dict : output [ j ] = labs_dict [ j ] . __dict__ output = pd . DataFrame . from_dict ( output ) output = output . transpose ( ) elif format . lower ( ) == "object" or format . lower ( ) == "obj" : output = labs else : output = labs if format . lower ( ) == "json" : output = json . dumps ( labs_dict ) return output
Gets data from all labs from makeinitaly.foundation.