datasources.tiktok_comments.search_tiktok_comments
Import scraped TikTok comment data
It's prohibitively difficult to scrape data from TikTok within 4CAT itself due to its aggressive rate limiting. Instead, import data collected elsewhere.
1""" 2Import scraped TikTok comment data 3 4It's prohibitively difficult to scrape data from TikTok within 4CAT itself due 5to its aggressive rate limiting. Instead, import data collected elsewhere. 6""" 7from datetime import datetime 8 9from backend.lib.search import Search 10from common.lib.item_mapping import MappedItem 11 12 13class SearchTikTokComments(Search): 14 """ 15 Import scraped TikTok comment data 16 """ 17 type = "tiktok-comments-search" # job ID 18 category = "Search" # category 19 title = "Import scraped Tiktok comment data" # title displayed in UI 20 description = "Import Tiktok comment data collected with an external tool such as Zeeschuimer." # description displayed in UI 21 extension = "ndjson" # extension of result file, used internally and in UI 22 is_from_zeeschuimer = True 23 24 # not available as a processor for existing datasets 25 accepts = [None] 26 references = [ 27 "[Zeeschuimer browser extension](https://github.com/digitalmethodsinitiative/zeeschuimer)", 28 "[Worksheet: Capturing TikTok data with Zeeschuimer and 4CAT](https://tinyurl.com/nmrw-zeeschuimer-tiktok)" 29 ] 30 31 def get_items(self, query): 32 """ 33 Run custom search 34 35 Not available for TikTok comments 36 """ 37 raise NotImplementedError("TikTok comment datasets can only be created by importing data from elsewhere") 38 39 @staticmethod 40 def map_item(item): 41 item_datetime = datetime.fromtimestamp(item["create_time"]).strftime("%Y-%m-%d %H:%M:%S") 42 thread_id = item["aweme_id"] if item["reply_id"] == "0" else item["reply_id"] 43 avatar_url = item["user"]["avatar_thumb"]["url_list"][0] 44 45 return MappedItem({ 46 "id": item["cid"], 47 "thread_id": thread_id, 48 "author": item["user"]["unique_id"], 49 "author_full": item["user"]["nickname"], 50 "author_avatar_url": avatar_url, 51 "body": item["text"], 52 "timestamp": item_datetime, 53 "unix_timestamp": item["create_time"], 54 "likes": item["digg_count"], 55 "replies": item.get("reply_comment_total", 0), 56 "post_id": item["aweme_id"], 57 "post_url": item["share_info"]["url"].split(".html")[0], 58 "post_body": item["share_info"]["title"], 59 "comment_url": item["share_info"]["url"], 60 "is_liked_by_post_author": "yes" if bool(item.get("author_pin")) else "no", 61 "is_sticky": "yes" if bool(item["stick_position"]) else "no", 62 "is_comment_on_comment": "no" if bool(item["reply_id"] == "0") else "yes", 63 "language_guess": item["comment_language"] 64 })
14class SearchTikTokComments(Search): 15 """ 16 Import scraped TikTok comment data 17 """ 18 type = "tiktok-comments-search" # job ID 19 category = "Search" # category 20 title = "Import scraped Tiktok comment data" # title displayed in UI 21 description = "Import Tiktok comment data collected with an external tool such as Zeeschuimer." # description displayed in UI 22 extension = "ndjson" # extension of result file, used internally and in UI 23 is_from_zeeschuimer = True 24 25 # not available as a processor for existing datasets 26 accepts = [None] 27 references = [ 28 "[Zeeschuimer browser extension](https://github.com/digitalmethodsinitiative/zeeschuimer)", 29 "[Worksheet: Capturing TikTok data with Zeeschuimer and 4CAT](https://tinyurl.com/nmrw-zeeschuimer-tiktok)" 30 ] 31 32 def get_items(self, query): 33 """ 34 Run custom search 35 36 Not available for TikTok comments 37 """ 38 raise NotImplementedError("TikTok comment datasets can only be created by importing data from elsewhere") 39 40 @staticmethod 41 def map_item(item): 42 item_datetime = datetime.fromtimestamp(item["create_time"]).strftime("%Y-%m-%d %H:%M:%S") 43 thread_id = item["aweme_id"] if item["reply_id"] == "0" else item["reply_id"] 44 avatar_url = item["user"]["avatar_thumb"]["url_list"][0] 45 46 return MappedItem({ 47 "id": item["cid"], 48 "thread_id": thread_id, 49 "author": item["user"]["unique_id"], 50 "author_full": item["user"]["nickname"], 51 "author_avatar_url": avatar_url, 52 "body": item["text"], 53 "timestamp": item_datetime, 54 "unix_timestamp": item["create_time"], 55 "likes": item["digg_count"], 56 "replies": item.get("reply_comment_total", 0), 57 "post_id": item["aweme_id"], 58 "post_url": item["share_info"]["url"].split(".html")[0], 59 "post_body": item["share_info"]["title"], 60 "comment_url": item["share_info"]["url"], 61 "is_liked_by_post_author": "yes" if bool(item.get("author_pin")) else "no", 62 "is_sticky": "yes" if bool(item["stick_position"]) else "no", 63 "is_comment_on_comment": "no" if bool(item["reply_id"] == "0") else "yes", 64 "language_guess": item["comment_language"] 65 })
Import scraped TikTok comment data
references =
['[Zeeschuimer browser extension](https://github.com/digitalmethodsinitiative/zeeschuimer)', '[Worksheet: Capturing TikTok data with Zeeschuimer and 4CAT](https://tinyurl.com/nmrw-zeeschuimer-tiktok)']
def
get_items(self, query):
32 def get_items(self, query): 33 """ 34 Run custom search 35 36 Not available for TikTok comments 37 """ 38 raise NotImplementedError("TikTok comment datasets can only be created by importing data from elsewhere")
Run custom search
Not available for TikTok comments
@staticmethod
def
map_item(item):
40 @staticmethod 41 def map_item(item): 42 item_datetime = datetime.fromtimestamp(item["create_time"]).strftime("%Y-%m-%d %H:%M:%S") 43 thread_id = item["aweme_id"] if item["reply_id"] == "0" else item["reply_id"] 44 avatar_url = item["user"]["avatar_thumb"]["url_list"][0] 45 46 return MappedItem({ 47 "id": item["cid"], 48 "thread_id": thread_id, 49 "author": item["user"]["unique_id"], 50 "author_full": item["user"]["nickname"], 51 "author_avatar_url": avatar_url, 52 "body": item["text"], 53 "timestamp": item_datetime, 54 "unix_timestamp": item["create_time"], 55 "likes": item["digg_count"], 56 "replies": item.get("reply_comment_total", 0), 57 "post_id": item["aweme_id"], 58 "post_url": item["share_info"]["url"].split(".html")[0], 59 "post_body": item["share_info"]["title"], 60 "comment_url": item["share_info"]["url"], 61 "is_liked_by_post_author": "yes" if bool(item.get("author_pin")) else "no", 62 "is_sticky": "yes" if bool(item["stick_position"]) else "no", 63 "is_comment_on_comment": "no" if bool(item["reply_id"] == "0") else "yes", 64 "language_guess": item["comment_language"] 65 })
Inherited Members
- backend.lib.worker.BasicWorker
- BasicWorker
- INTERRUPT_NONE
- INTERRUPT_RETRY
- INTERRUPT_CANCEL
- queue
- log
- manager
- interrupted
- modules
- init_time
- name
- run
- clean_up
- request_interrupt
- is_4cat_class
- backend.lib.search.Search
- max_workers
- prefix
- return_cols
- import_error_count
- import_warning_count
- process
- search
- import_from_file
- items_to_csv
- items_to_ndjson
- items_to_archive
- backend.lib.processor.BasicProcessor
- db
- job
- dataset
- owner
- source_dataset
- source_file
- config
- is_running_in_preset
- filepath
- work
- after_process
- remove_files
- abort
- iterate_proxied_requests
- push_proxied_request
- flush_proxied_requests
- iterate_archive_contents
- unpack_archive_contents
- extract_archived_file_by_name
- write_csv_items_and_finish
- write_archive_and_finish
- create_standalone
- save_annotations
- map_item_method_available
- get_mapped_item
- is_filter
- get_options
- get_status
- is_top_dataset
- is_from_collector
- get_extension
- is_rankable
- exclude_followup_processors
- is_4cat_processor