Skip to content

Auto-translated map_item updates from 4CAT: instagram - #107

Draft
4cat-to-zeeschuimer-automation-pr[bot] wants to merge 1 commit into
masterfrom
auto/4cat-map-item-sync-instagram
Draft

4cat-to-zeeschuimer-automation-pr[bot] wants to merge 1 commit into
masterfrom
auto/4cat-map-item-sync-instagram

Conversation

@4cat-to-zeeschuimer-automation-pr

Copy link
Copy Markdown
Contributor

🤖 This PR was auto-generated by the 4CAT map_item sync workflow. The JavaScript was produced by an LLM and requires human review before merging — including manual fixes for any lint warnings flagged below.

Generation parameters

  • Model: gpt-oss-120b (provider: litellm)
  • Total LLM time: 50.01s
  • Trigger: push of 4a8c72d to 4CAT master (module: instagram).

Summary

  • ✅ 1 translated
  • ❌ 0 failed
  • ❔ 0 skipped
Datasource Module Time Warnings
datasources/instagram/search_instagram.py modules/instagram.js 50.0s —

datasources/instagram/search_instagram.py -> modules/instagram.js (50.0s)

LLM commentary:

Implemented all static helpers and constants used by map_item, including regex for hashtags, timestamp extraction using BigInt, and author handling. Each parser (polaris, graph, itemlist) mirrors the Python logic, using globals like MappedItem, MissingMappedField, MapItemException, readable_url, formatUtcTimestamp, value_or_missing, and py_get. Truthy checks and array handling follow JavaScript semantics, and all Python f‑strings are replaced with template literals. No external imports are required.

Python diff
diff --git a/datasources/instagram/search_instagram.py b/datasources/instagram/search_instagram.py
index be99c0ea..2c150407 100644
--- a/datasources/instagram/search_instagram.py
+++ b/datasources/instagram/search_instagram.py
@@ -47,6 +47,20 @@ class SearchInstagram(Search):
             return ""
         return ",".join(SearchInstagram.HASHTAG_REGEX.findall(caption))
 
+    @staticmethod
+    def extract_timestamp(post_id) -> int:
+        """
+        Instagram post ID embeds timestamp of publication!
+
+        See https://slang.cx/instagram-id
+        :param post_id: Numerical post ID (i.e. not the string)
+        :retur int: timestamp
+        """
+        post_id = int(post_id)
+        instagram_epoch = 1314220021
+        embedded_timestamp = (post_id >> (64 - 41)) / 1000
+        return round(instagram_epoch + embedded_timestamp)
+
     @staticmethod
     def get_author(node):
         """
@@ -209,6 +223,11 @@ class SearchInstagram(Search):
         unix_at = MissingMappedField(0)
         # 2026-2-24 node["caption"]["text"] 
         caption = MissingMappedField("") if "caption" not in node else "" if not node.get("caption") else node["caption"]["text"]
+
+        # we have no direct timestamp, but we can extract it from the post ID if available
+        if "pk" in node:
+            unix_at = SearchInstagram.extract_timestamp(node["pk"])
+            collected_at = datetime.datetime.fromtimestamp(unix_at).strftime("%Y-%m-%d %H:%M:%S"),
         
 
         author = SearchInstagram.get_author(node)
@@ -536,8 +555,9 @@ class SearchInstagram(Search):
             unix_at = node["taken_at"]
         else:
             # grid and thumbnail views leave the post date out
-            collected_at = MissingMappedField(0)
-            unix_at = MissingMappedField(0)
+            # but we can get it from the post ID!
+            unix_at = SearchInstagram.extract_timestamp(node["pk"])
+            collected_at = datetime.datetime.fromtimestamp(unix_at).strftime("%Y-%m-%d %H:%M:%S")
 
         mapped_item = {
             # Post and caption

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant