Skip to content
Snippets Groups Projects
Commit 3b036e7a authored by Jan Eggers's avatar Jan Eggers
Browse files

cursor Param in check_handle()

parent a4799055
No related branches found
No related tags found
No related merge requests found
...@@ -10,7 +10,7 @@ authors = [ ...@@ -10,7 +10,7 @@ authors = [
maintainers = [ maintainers = [
{name = "Jan Eggers", email = "jan.eggers@hr.de"}, {name = "Jan Eggers", email = "jan.eggers@hr.de"},
] ]
version = "0.1.4" # Neue Versionsnummern für pip-Update version = "0.1.4.1" # Neue Versionsnummern für pip-Update
description = "Bluesky-Konten auf KI-Inhalte checken" description = "Bluesky-Konten auf KI-Inhalte checken"
requires-python = ">=3.8" requires-python = ">=3.8"
dependencies = [ dependencies = [
......
...@@ -117,12 +117,11 @@ def call_get_profile(handle: str) -> list: ...@@ -117,12 +117,11 @@ def call_get_profile(handle: str) -> list:
return None return None
return response[''] return response['']
def fetch_user_posts(handle: str, limit: int = 100) -> list: def fetch_user_posts(handle: str, limit: int = 100, cursor = None) -> list:
profile = call_get_profile(handle) profile = call_get_profile(handle)
did = profile['did'] did = profile['did']
posts = [] posts = []
# Fetch timeline for the user (latest posts first) # Fetch timeline for the user (latest posts first)
cursor = None
while len(posts) < limit: while len(posts) < limit:
feed = call_get_author_feed(did, limit, cursor) feed = call_get_author_feed(did, limit, cursor)
if not feed['feed']: if not feed['feed']:
...@@ -221,63 +220,3 @@ def find_handles(text): ...@@ -221,63 +220,3 @@ def find_handles(text):
handles = [a['handle'] for a in actors['actors']] handles = [a['handle'] for a in actors['actors']]
return handles return handles
if __name__ == "__main__":
# Bluesky-
handle_str = input("Erstes Handle mit diesen Zeichen wählen: ")
handle = find_handles(handle_str)[0]
print(handle)
# Diese Funktion holt die Infos zum Profil 'handle':
# Erwartet einen String, gibt ein dict zurück.
# Beschreibung: https://docs.bsky.app/docs/api/app-bsky-actor-get-profile
# Manchmal existieren Felder wie 'description' nicht.
profile = call_get_profile(handle)
author = profile['did']
print(author)
# Diese Funktion holt die Posts.
# 'author' darf irgendwas sein: handle, did... wir nehmen die did
# Gibt ein dict zurück: im Schlüssel 'feed' sind die einzelnen Posts gespeichert,
# im Key 'cursor' gibt es das Datum des frühesten abgefragten Posts zurück (es sei denn,
# es sind weniger Posts als limit, dann ist cursor leer.)
# Beschreibung: https://docs.bsky.app/docs/api/app-bsky-feed-get-author-feed
posts = call_get_author_feed(author, limit = limit)
# In diesem Demo-Programm werden die Posts hier noch nicht ausgewertet.
# Das passiert in der Extra-Funktion check_handle unten.
print(posts['cursor'])
# Funktion prüft die letzten ```limit``` Posts (voreingestellt auf 20)
# Erwartet ein Handle oder ein did - wir nehmen DID
# Gibt ein Dataframe zurück; Struktur ist oben in der Funktion beschrieben.
# Wichtigster Punkt: Ergebnis des KI-Checks in den Spalten
# - 'detectora_ai_score': Detectora-Score des Post-Textes (als real)
# - 'aiornot_ai_score':
df = check_handle(author, limit = limit)
n_posts = len(df)
print(f'\n\nAnalyse des Kontos @{handle} ({profile['displayName']}) seit {profile['createdAt']}- {profile['followersCount']} Follower')
print(f'{profile.get('description','---')}\n')
print(f'Anzahl der analysierten Posts: {n_posts}')
print(f"Durchschnittliche KI-Text-Wahrscheinlichkeit: {df['detectora_ai_score'].mean()}")
detectora_posts_df = df[df['detectora_ai_score'] >= d_thresh]
print(f"Anzahl von Posts über einer detectora-Schwelle von {d_thresh*100:.1f}%: {len(detectora_posts_df)}")
image_posts = [post for post in df['aiornot_ai_score'].to_list() if post is not None]
# Liste auspacken, nur die Dicts ohne None-Elemente
image_list = [item for sublist in image_posts for item in sublist]
ai_list = [item for item in image_list if item['aiornot_score']!='human']
if len(image_list) == 0:
p_ai = 0
else:
p_ai = len(ai_list)/len(image_list) * 100
print(f"Anzahl der Bilder: {len(image_list)}, verdächtig: {len(ai_list)} ({p_ai:.1f})%")
# Jetzt die Daten abspeichern
# Fals das Directory nicht existiert, anlegen
if not os.path.exists('bsky-checks'):
os.makedirs('bsky-checks')
# Read existing file if it exists
filename = f'bsky-checks/{handle}.csv'
if os.path.exists(filename):
existing_df = pd.read_csv(filename)
df = pd.concat([existing_df, df]).drop_duplicates(subset=['uri']).reset_index(drop=True)
df.to_csv(f'bsky-checks/{handle}.csv', index=False) # Save to CSV for example
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment