From 23695fb46812b67412543457ceea3e04c8b3d31a Mon Sep 17 00:00:00 2001 From: Logan Williams Date: Fri, 11 Dec 2020 10:18:23 +0100 Subject: [PATCH] Add CSV output option --- README.md | 6 ++++-- instagram-locations.py | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 89a6fe0..75382fc 100644 --- a/README.md +++ b/README.md @@ -14,15 +14,17 @@ Note that this requires an Instagram session ID in order to work! See below for ### Other output formats +Using the `--csv ` command line argument, the list can be saved as a CSV file. + Using the `--geojson ` command line argument, the list can be saved as a GeoJSON file for other geospatial applications. Using the `--map ` command line argument, a simple Leaflet map is made to visualize the locations of the returned points. ![Example of map visualization](docs/map-example.png) -Multiple types of output can be generated. For example, the following command will search for Instagram locations, save the JSON list, a GeoJSON file, and a map for viewing the locations visually. +Multiple types of output can be generated. For example, the following command will search for Instagram locations, save the JSON list, a CSV file, and a map for viewing the locations visually. -```python3 instagram-locations.py --session "3888090946%3AhdKd2fA8d72dqD%3A16" --lat 32.22 --lng -110.97 --json locs.json --geojson locs.geojson --map map.html``` +```python3 instagram-locations.py --session "3888090946%3AhdKd2fA8d72dqD%3A16" --lat 32.22 --lng -110.97 --json locs.json --csv locs.csv --map map.html``` ## Getting an Instagram session ID diff --git a/instagram-locations.py b/instagram-locations.py index 26d452d..2392e55 100644 --- a/instagram-locations.py +++ b/instagram-locations.py @@ -1,5 +1,6 @@ import requests import numpy as np +import pandas as pd import argparse import json from string import Template @@ -117,6 +118,7 @@ def main(): parser.add_argument("--json", action="store", dest="output") parser.add_argument("--geojson", action="store", dest="geojson") parser.add_argument("--map", action="store", dest="map") + parser.add_argument("--csv", action="store", dest="csv") parser.add_argument("--lat", action="store", dest="lat") parser.add_argument("--lng", action="store", dest="lng") @@ -140,6 +142,11 @@ def main(): f.write(viz) f.close() + if (args.csv): + df = pd.DataFrame(locations) + df['url'] = df['external_id'].apply(lambda v: 'https://www.instagram.com/explore/locations/' + str(v)) + df.to_csv(args.csv) + if __name__ == "__main__": main()