Add CSV output option

This commit is contained in:
Logan Williams
2020-12-11 10:18:23 +01:00
parent 26eeb50b89
commit 23695fb468
2 changed files with 11 additions and 2 deletions

View File

@@ -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 <output-location>` command line argument, the list can be saved as a CSV file.
Using the `--geojson <output-location>` command line argument, the list can be saved as a GeoJSON file for other geospatial applications.
Using the `--map <output-location>` 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

View File

@@ -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()