MCPcopy
hub / github.com/dreammis/social-auto-upload / generate_schedule_time_next_day

Function generate_schedule_time_next_day

utils/files_times.py:41–83  ·  view source on GitHub ↗

Generate a schedule for video uploads, starting from the next day. Args: - total_videos: Total number of videos to be uploaded. - videos_per_day: Number of videos to be uploaded each day. - daily_times: Optional list of specific times of the day to publish the videos. - tim

(total_videos, videos_per_day, daily_times=None, timestamps=False, start_days=0)

Source from the content-addressed store, hash-verified

39
40
41def generate_schedule_time_next_day(total_videos, videos_per_day, daily_times=None, timestamps=False, start_days=0):
42 """
43 Generate a schedule for video uploads, starting from the next day.
44
45 Args:
46 - total_videos: Total number of videos to be uploaded.
47 - videos_per_day: Number of videos to be uploaded each day.
48 - daily_times: Optional list of specific times of the day to publish the videos.
49 - timestamps: Boolean to decide whether to return timestamps or datetime objects.
50 - start_days: Start from after start_days.
51
52 Returns:
53 - A list of scheduling times for the videos, either as timestamps or datetime objects.
54 """
55 if videos_per_day <= 0:
56 raise ValueError("videos_per_day should be a positive integer")
57
58 if daily_times is None:
59 # Default times to publish videos if not provided
60 daily_times = [6, 11, 14, 16, 22]
61
62 if videos_per_day > len(daily_times):
63 raise ValueError("videos_per_day should not exceed the length of daily_times")
64
65 # Generate timestamps
66 schedule = []
67 current_time = datetime.now()
68
69 for video in range(total_videos):
70 day = video // videos_per_day + start_days + 1 # +1 to start from the next day
71 daily_video_index = video % videos_per_day
72
73 # Calculate the time for the current video
74 hour = daily_times[daily_video_index]
75 time_offset = timedelta(days=day, hours=hour - current_time.hour, minutes=-current_time.minute,
76 seconds=-current_time.second, microseconds=-current_time.microsecond)
77 timestamp = current_time + time_offset
78
79 schedule.append(timestamp)
80
81 if timestamps:
82 schedule = [int(time.timestamp()) for time in schedule]
83 return schedule

Calls

no outgoing calls

Tested by

no test coverage detected