Skip to content

HaraldoFilho/FlickrMap

Repository files navigation

Flickr Map

This script generates a map with markers for all photos in a user's Flickr™ photostream. Click here to see an example.

Installation

The script was developed to run on Linux systems and need Python 3.x to run.

To start, open a terminal and execute the following commands:

git clone https://github.com/HaraldoFilho/FlickrMap.git
cd FlickrMap

The script uses Flickr and Mapbox APIs. To get and use these APIs follow the instructions below.

Flickr API key

First, install the flickrapi package by typing in a terminal:

% pip3 install flickrapi

Now, get an API key by visiting the Flickr API key request page.

After that, create a file api_credentials.py with the following code and with the obtained values:

api_key = u'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
api_secret = u'xxxxxxxxxxxxxxx'
user_id = 'XXXXXXXXXXXX'

Then, authenticate on Flickr by running:

% ./auth2flickr.py

A web browser will be opened to get the user approval (in a non-graphical environment, just copy and paste the authorization url in any external web browser). After approve, type in the terminal the generated code.

Mapbox API access token

Get an access token by visiting the Create an access token page on Mapbox website.

Give a name to the token (e.g.: "Flickr Photos Map") and click on "Create token".

Then, include the generated code in the file mapbox_token.js:

var mapbox_token =
'<-- include the mapbox access token here -->'

Configuration

Open the file 'config.py' and edit it as following:

Add the user for whom the map will be generated. It can be the user alias or id.

# user alias or id
user = '<-- include user alias or id here -->'

The map can be generated for just the photos on a user's photoset. In this case, add a valid photoset id to the photoset_id variable.:

# Photoset id:
# If this is defined the map will
# be generated for the photoset
# To generate for entire user's
# photostream, leave it empty
photoset_id = ''

If the variable is empty or have a invalid id the map will be generated for the entire user's photostream.

By default, the script will generate the map marking only the public photos on the user's photostream, and those with a geolocation set as visible to anyone. This can be changed by editing the variables photo_privacy and/or geo_privacy:

# Photo Privacy Filter:
# 0 = all photos (public and private)
# 1 = public photos
# 2 = private photos visible to friends
# 3 = private photos visible to family
# 4 = private photos visible to friends & family
# 5 = completely private photos
photo_privacy = 1

# Geolocation Privacy Filter:
# 0 = All
# 1 = Anyone (Recommended)
# 2 = Your contacts
# 3 = Your friends
# 4 = Your family
# 5 = Your friends and family
# 6 = Only you
geo_privacy = 1

But only the authenticated user will be able to see the privated photos of your own photostream, i.e. when generating for a different user only the public photos will be visible, independently of this configuration.

There is one more option that can be changed, the variable dont_map_tag. To exclude a photo from the map, define a tag in this variable and add the same tag to the photo. The default tag is DontMap:

# Photos with this tag
# won't be included on map
dont_map_tag = 'DontMap'

Usage

Just run the script:

% ./generate-map-data.py

The output will be like this:

Generating map for 'Haraldo Albergaria'
1065 photos in the photostream
Extracting photo coordinates and ids...
Batch 3/3 | 958 photo(s) in 530 marker(s)
Adding marker(s) to map...
530 new marker(s) will be added to the map
Added marker 530/530
Finished!

Three files are generated:

  • locations.py: Contains all the markers information, as coordinates and photos attached to them.
  • countries.py: List of countries where the photos were taken, including number of places and photos for each place.
  • user.py: Basic user information, such as user id, name, avatar url, photostream url, number of markers and photos on map.

After the script finishes, open the file index.html in a web browser, such as Google Chrome and Microsoft Edge (doesn't work on Internet Explorer and has not been tested on other browsers) to see the map.

It is possible to make customizations on the map, by coding them in Javascript in the file custom.js and adding any includes, such as styles and additional javascript files in the appropriate field in 'index.html' file:

<!-- Begin of customization includes -->

<!-- End of customization includes -->

An example of a customization file can be seen here and its result, where was added a panel with visited countries flags, which zoom in to the country when clicked, can be seen here.