update html
authorClaromes <claromes@hey.com>
Tue, 4 Jun 2024 22:09:20 +0000 (19:09 -0300)
committerClaromes <claromes@hey.com>
Tue, 4 Jun 2024 22:09:20 +0000 (19:09 -0300)
waybacktweets/export_tweets.py
waybacktweets/main.py
waybacktweets/viz_tweets.py

index fcd648ce6655022b93ff13037e777a3df3e35631..40b04e6ad8df40b5269dea88b05e0a2801ed4a19 100644 (file)
@@ -46,7 +46,6 @@ class TweetsExporter:
         data_transposed = self.transpose_matrix(self.data)
 
         df = pd.DataFrame(data_transposed, columns=self.metadata_options)
-
         df = df.sort_values(by="archived_timestamp", ascending=self.ascending)
 
         return df
index 66bdfb304639eb031a88aad00e504d3fc12efc4b..aa2203713724a743dc217766162cd7a028af9480 100644 (file)
@@ -34,9 +34,9 @@ def main():
 
             exporter = TweetsExporter(parsed_tweets, username,
                                       metadata_options, ascending)
-            exporter.save_to_csv()
+            exporter.save_to_csv()
             # exporter.save_to_json()
-            exporter.save_to_html()
+            exporter.save_to_html()
 
             print(
                 f'\nNeed help? Open an issue: https://github.com/claromes/waybacktweets/issues.'
index ef14a384752d2c9cc070a2276893a1e9d6564e09..ff19364f702bbad38c791c6fcef8cbb1016fafce 100644 (file)
@@ -23,9 +23,11 @@ class HTMLTweetsVisualizer:
         html += '.container { display: flex; flex-wrap: wrap; gap: 20px; }\n'
         html += '.tweet { flex: 0 1 calc(33.33% - 20px); background-color: #fff; border: 1px solid #e1e8ed; border-radius: 10px; padding: 15px; overflow-wrap: break-word; margin: auto; }\n'
         html += '.tweet strong { font-weight: bold; }\n'
-        html += '.tweet a { color: #1da1f2; text-decoration: none; }\n'
+        html += '.tweet a { color: #ef5552; text-decoration: none; }\n'
+        html += '.content { color: #ef5552; }\n'
         html += '.tweet a:hover { text-decoration: underline; }\n'
-        html += 'h1 { text-align: center; }\n'
+        html += 'h1, h3 { text-align: center; }\n'
+        html += 'iframe { width: 600px; height: 600px; }\n'
         html += '</style>\n'
         html += '</head>\n<body>\n'
         html += f'<h1>@{self.username} archived tweets</h1>\n'
@@ -33,23 +35,34 @@ class HTMLTweetsVisualizer:
 
         for tweet in self.json_content:
             html += '<div class="tweet">\n'
-            html += f'<p><strong>Archived Timestamp:</strong> {tweet["archived_timestamp"]}</p>\n'
+
+            if tweet["archived_mimetype"] != 'application/json':
+                html += f'<iframe src="{tweet["parsed_archived_tweet_url"]}" frameborder="0" scrolling="auto"></iframe>\n'
+
+            html += f'<p><a href="{tweet["original_tweet_url"]}" target="_blank"><strong>Original Tweet↗</strong></a> · \n'
+            html += f'<a href="{tweet["parsed_tweet_url"]}" target="_blank"><strong>Parsed Tweet↗</strong></a> · \n'
+            html += f'<a href="{tweet["archived_tweet_url"]}" target="_blank"><strong>Archived Tweet↗</strong></a> · \n'
+            html += f'<a href="{tweet["parsed_archived_tweet_url"]}" target="_blank"><strong>Parsed Archived Tweet↗</strong></a></p>\n'
+
+            if tweet["available_tweet_text"]:
+                html += f'<p><strong class="content">Available Tweet Content:</strong> {tweet["available_tweet_text"]}</p>\n'
+                html += f'<p><strong class="content">Available Tweet Is Retweet:</strong> {tweet["available_tweet_is_RT"]}</p>\n'
+                html += f'<p><strong class="content">Available Tweet Username:</strong> {tweet["available_tweet_username"]}</p>\n'
+
+            if tweet["archived_mimetype"] == 'application/json':
+                html += f'<p><strong class="content">Parsed Tweet Text (application/json):</strong> {tweet["parsed_tweet_text_mimetype_json"]}</p>\n'
+
+            html += f'<br>\n'
             html += f'<p><strong>Archived URL Key:</strong> {tweet["archived_urlkey"]}</p>\n'
-            html += f'<p><strong>Tweet:</strong> <a href="{tweet["tweet"]}">{tweet["tweet"]}</a></p>\n'
-            html += f'<p><strong>Archived Tweet:</strong> <a href="{tweet["archived_tweet"]}">{tweet["archived_tweet"]}</a></p>\n'
-            html += f'<p><strong>Parsed Tweet:</strong> <a href="{tweet["parsed_tweet"]}">{tweet["parsed_tweet"]}</a></p>\n'
-            html += f'<p><strong>Parsed Tweet Mimetype JSON:</strong> {tweet["parsed_tweet_mimetype_json"]}</p>\n'
-            html += f'<p><strong>Parsed Archived Tweet:</strong> <a href="{tweet["parsed_archived_tweet"]}">{tweet["parsed_archived_tweet"]}</a></p>\n'
-            html += f'<p><strong>Archived Mimetype:</strong> {tweet["archived_mimetype"]}</p>\n'
+            html += f'<p><strong>Archived Timestamp:</strong> {tweet["archived_timestamp"]}</p>\n'
+            html += f'<p><strong>Archived mimetype:</strong> {tweet["archived_mimetype"]}</p>\n'
             html += f'<p><strong>Archived Statuscode:</strong> {tweet["archived_statuscode"]}</p>\n'
             html += f'<p><strong>Archived Digest:</strong> {tweet["archived_digest"]}</p>\n'
             html += f'<p><strong>Archived Length:</strong> {tweet["archived_length"]}</p>\n'
-            html += f'<p><strong>Available Tweet Content:</strong> {tweet["available_tweet_content"]}</p>\n'
-            html += f'<p><strong>Available Tweet Is Retweet:</strong> {tweet["available_tweet_is_RT"]}</p>\n'
-            html += f'<p><strong>Available Tweet Username:</strong> {tweet["available_tweet_username"]}</p>\n'
             html += '</div>\n'
 
         html += '</div>\n'
+        html += f'<h3>generated by <a href="https://github.com/claromes/waybacktweets" target="_blank">Wayback Tweets↗</a></h3>\n'
         html += '</body>\n</html>'
 
         return html