Browse Source

Add alg_growth_common

StrayWarrior 4 months ago
parent
commit
7091e5c252
1 changed files with 26 additions and 0 deletions
  1. 26 0
      alg_growth_common.py

+ 26 - 0
alg_growth_common.py

@@ -0,0 +1,26 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+# vim:fenc=utf-8
+#
+# Copyright © 2024 StrayWarrior <i@straywarrior.com>
+
+"""
+Common functions for growth jobs
+"""
+
+UNSAFE_VIDEO_IDS = [14403867, 13696461, 13671819, 13587868, 13680796, 14050873,
+                    26348326, 28623786]
+
+def check_unsafe_video(df, force_replace=True):
+    unsafe_video_condition = ','.join([str(x) for x in UNSAFE_VIDEO_IDS])
+    unsafe_rows = df.query(f'video_id in ({unsafe_video_condition})')
+    if len(unsafe_rows) > 0:
+        print(unsafe_rows)
+        if not force_replace:
+            raise Exception("video unsafe")
+        df.loc[unsafe_rows.index, 'video_id'] = 20463342
+
+def filter_unsafe_video(df):
+    unsafe_video_condition = ','.join([str(x) for x in UNSAFE_VIDEO_IDS])
+    df = df.query(f'video_id not in ({unsafe_video_condition})')
+    return df