Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
betsybookwyrm committed May 22, 2023
1 parent 939f5a5 commit 04bb127
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/tidy_tweet/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ def initialise_sqlite(
logger.debug("Created database tables: " + str(created_tables))
assert len(created_tables) == len(mapping.create_table_statements)
cursor.execute("create table schema_version (schema_version text)")
cursor.execute("insert into schema_version values (:version)", {"version": mapping.SCHEMA_VERSION})
cursor.execute(
"insert into schema_version values (:version)",
{"version": mapping.SCHEMA_VERSION},
)

logger.info("The database schema has been initialised")

Expand Down
6 changes: 4 additions & 2 deletions src/tidy_tweet/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
logger = getLogger(__name__)


def _load_page_object(file_name: str, page_json: Mapping, connection: sqlite3.Connection):
def _load_page_object(
file_name: str, page_json: Mapping, connection: sqlite3.Connection
):
"""
Takes a page of twarc Twitter API results and loads it into the database.
Expand All @@ -31,7 +33,7 @@ def _load_page_object(file_name: str, page_json: Mapping, connection: sqlite3.Co
# Write this first so we can get the page id
db.execute(
mapping.sql_by_table["results_page"]["insert"],
mapping.map_page_metadata(file_name, twitter_metadata, twarc_metadata)
mapping.map_page_metadata(file_name, twitter_metadata, twarc_metadata),
)
page_info = (file_name, db.lastrowid)

Expand Down
18 changes: 12 additions & 6 deletions src/tidy_tweet/tweet_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def map_user(user_json, source_file, page_id) -> Dict[str, List[Dict]]:
"location": user_json.get("location", None),
"pinned_tweet_id": user_json.get("pinned_tweet_id", None),
"source_file": source_file,
"page_id": page_id
"page_id": page_id,
}

mappings = {"user": [user_map]}
Expand Down Expand Up @@ -434,7 +434,9 @@ def map_user(user_json, source_file, page_id) -> Dict[str, List[Dict]]:
}


def map_tweet(tweet_json, directly_collected: bool, source_file: str, page_id) -> Dict[str, List[Dict]]:
def map_tweet(
tweet_json, directly_collected: bool, source_file: str, page_id
) -> Dict[str, List[Dict]]:
tweet_map = {
"id": tweet_json["id"],
"author_id": tweet_json["author_id"],
Expand All @@ -452,7 +454,7 @@ def map_tweet(tweet_json, directly_collected: bool, source_file: str, page_id) -
"retweet_count": tweet_json["public_metrics"]["retweet_count"],
"directly_collected": directly_collected,
"source_file": source_file,
"page_id": page_id
"page_id": page_id,
}

if "in_reply_to_user_id" in tweet_json:
Expand Down Expand Up @@ -521,9 +523,11 @@ def map_tweet(tweet_json, directly_collected: bool, source_file: str, page_id) -
:twarc_version, :tidy_tweet_version,
:additional_metadata
)
"""
""",
}
sql_views["results_file"] = """
sql_views[
"results_file"
] = """
create view results_file as
select
file_name,
Expand Down Expand Up @@ -574,7 +578,9 @@ def map_tweet(tweet_json, directly_collected: bool, source_file: str, page_id) -
# return metadata


def map_page_metadata(filename:str, page_metadata_json: Dict, twarc_metadata_json: Dict) -> Dict:
def map_page_metadata(
filename: str, page_metadata_json: Dict, twarc_metadata_json: Dict
) -> Dict:
metadata = {"file_name": filename}

# Tidy tweet metadata
Expand Down
1 change: 1 addition & 0 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ def test_get_tidy_tweet_version():

assert version != "unknown" and version != "unspecified"


# TODO: metadata test

0 comments on commit 04bb127

Please sign in to comment.