Skip to content

Commit

Permalink
Change default output behavior, search in a tighter radius
Browse files Browse the repository at this point in the history
  • Loading branch information
loganwilliams committed Apr 8, 2024
1 parent 9604763 commit 38419cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
21 changes: 13 additions & 8 deletions instagram_locations/instagram_locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,12 @@ def get_instagram_locations_by_query(query):

# queries the instagram location API for several points around a central lat/lng
# in order to return additional results
def get_fuzzy_locations(lat, lng, cookie, sigma=2):
def get_fuzzy_locations(lat, lng, cookie, sigma=0):
locs = get_instagram_locations(lat, lng, cookie)
print(locs)
loc_ids = {v["external_id"] for v in locs if "external_id" in v}

std_lat = pstdev([v["lat"] for v in locs if "lat" in v])
std_lng = pstdev([v["lng"] for v in locs if "lng" in v])
std_lat = pstdev([v["lat"] for v in locs if "lat" in v]) / 8.0
std_lng = pstdev([v["lng"] for v in locs if "lng" in v]) / 8.0

# filter to avoid calling with both lat and lng deltas equal zero (which would duplicate the call
# to obtain the initial loc)
Expand Down Expand Up @@ -213,9 +212,12 @@ def main():
parser.add_argument("--lng", action="store", dest="lng")
parser.add_argument("--date", action="store", dest="date")
parser.add_argument("--ids", action="store", dest="dump_ids")
parser.add_argument("--more", action="store_true", dest="more")

args = parser.parse_args()

sigma = 2 if args.more else 0

cookie = args.cookie
# If user run command without cookie we are trying to perform automated flow to acquire the cookie
if not cookie:
Expand All @@ -225,7 +227,10 @@ def main():
if args.date is not None:
date_var = "?max_id=" + encode_date(args.date)

locations = get_fuzzy_locations(float(args.lat), float(args.lng), cookie)
locations = get_fuzzy_locations(float(args.lat), float(args.lng), cookie, sigma=sigma)

for i in locations:
i["url"] = f"https://www.instagram.com/explore/locations/{i['external_id']}{date_var}"

if args.output:
json.dump(locations, open(args.output, "w"))
Expand All @@ -242,9 +247,6 @@ def main():
f.close()

if args.csv:
for i in locations:
i["url"] = f"https://www.instagram.com/explore/locations/{i['external_id']}{date_var}"

# leading empty string for 'id' column is for backward compatibility since that's the pandas behavior.
fieldnames = ["", "name", "external_id", "external_id_source", "lat", "lng", "address", "minimum_age", "url"]

Expand All @@ -259,6 +261,9 @@ def main():
ids = map(lambda loc: str(loc["external_id"]), locations)
with open(args.dump_ids, "w") as f:
f.write("\n".join(ids))

if not args.dump_ids and not args.csv and not args.map and not args.geojson and not args.output:
print('\n'.join([f"{loc['name']} ({loc['url']})" for loc in locations]))


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions instagram_locations/version.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

_MAJOR = "1"
_MINOR = "4"
_MINOR = "5"
# On main and in a nightly release the patch should be one ahead of the last
# released build.
_PATCH = "2"
_PATCH = "1"
# This is mainly for nightly builds which have the suffix ".dev$DATE". See
# https://semver.org/#is-v123-a-semantic-version for the semantics.
_SUFFIX = ""
Expand Down

0 comments on commit 38419cd

Please sign in to comment.