Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
Update.
  • Loading branch information
JackTildeD committed Mar 27, 2024
1 parent 2e5c1f2 commit 2bcf1d1
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 7 deletions.
52 changes: 52 additions & 0 deletions gallery_dl/extractor/tumblr.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
from datetime import datetime, date, timedelta
import re

import os
import sys
import time
import math
import random
import datetime
from pathlib import Path

BASE_PATTERN = (
r"(?:tumblr:(?:https?://)?([^/]+)|"
Expand All @@ -25,6 +32,50 @@
"text", "quote", "link", "answer", "video", "audio", "photo", "chat"))


# --- 80 cols ---------------------------------------------------------------- #


def sleeping_time() -> bool:
current_time = datetime.datetime.now().time()
start_time = datetime.datetime.strptime("23:00", "%H:%M").time()
end_time = datetime.datetime.strptime("08:00", "%H:%M").time()
# Check if the current time is between 11:00 PM and 8:00 AM
is_between = start_time <= current_time or current_time <= end_time
return is_between


def go_to_bed() -> None:
if sleeping_time():
print(
"Program is going to bed for today."
)
while sleeping_time():
time.sleep(60)
return


def wait_inbetween_calls() -> None:
wait_time = max(0, random.gauss(mu = 120, sigma = 30))
print(
"Waiting for extra time inbetween retriving tweets."
+ f" ({wait_time:.3f}s)"
)
time.sleep(wait_time)
go_to_bed()
return


def wait_inbetween_downloads():
wait_time = max(0, random.gauss(mu = 120, sigma = 30))
print(
"Waiting for extra time inbetween downloading media."
+ f" ({wait_time:.3f}s)"
)
time.sleep(wait_time)
go_to_bed()
return


class TumblrExtractor(Extractor):
"""Base class for tumblr extractors"""
category = "tumblr"
Expand Down Expand Up @@ -402,6 +453,7 @@ def likes(self, blog):
return self._pagination(blog, "/likes", params, key="liked_posts")

def _call(self, endpoint, params, **kwargs):
wait_inbetween_calls()
url = self.ROOT + endpoint
kwargs["params"] = params

Expand Down
52 changes: 52 additions & 0 deletions gallery_dl/extractor/tumblrgallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,61 @@
from .common import GalleryExtractor
from .. import text

import os
import sys
import time
import math
import random
import datetime
from pathlib import Path

BASE_PATTERN = r"(?:https?://)?tumblrgallery\.xyz"


# --- 80 cols ---------------------------------------------------------------- #


def sleeping_time() -> bool:
current_time = datetime.datetime.now().time()
start_time = datetime.datetime.strptime("23:00", "%H:%M").time()
end_time = datetime.datetime.strptime("08:00", "%H:%M").time()
# Check if the current time is between 11:00 PM and 8:00 AM
is_between = start_time <= current_time or current_time <= end_time
return is_between


def go_to_bed() -> None:
if sleeping_time():
print(
"Program is going to bed for today."
)
while sleeping_time():
time.sleep(60)
return


def wait_inbetween_calls() -> None:
wait_time = max(0, random.gauss(mu = 120, sigma = 30))
print(
"Waiting for extra time inbetween retriving tweets."
+ f" ({wait_time:.3f}s)"
)
time.sleep(wait_time)
go_to_bed()
return


def wait_inbetween_downloads():
wait_time = max(0, random.gauss(mu = 120, sigma = 30))
print(
"Waiting for extra time inbetween downloading media."
+ f" ({wait_time:.3f}s)"
)
time.sleep(wait_time)
go_to_bed()
return


class TumblrgalleryExtractor(GalleryExtractor):
"""Base class for tumblrgallery extractors"""
category = "tumblrgallery"
Expand Down
20 changes: 13 additions & 7 deletions gallery_dl/extractor/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@


def sleeping_time() -> bool:
# Get the current local time
current_time = datetime.datetime.now().time()
# Define the start and end times
start_time = datetime.datetime.strptime("23:00", "%H:%M").time()
end_time = datetime.datetime.strptime("08:00", "%H:%M").time()
# Check if the current time is between 11:00 PM and 8:00 AM
Expand All @@ -43,23 +41,31 @@ def sleeping_time() -> bool:

def go_to_bed() -> None:
if sleeping_time():
print("Program is going to bed for today.")
while sleeping_time():
time.sleep(60)
print(
"Program is going to bed for today."
)
while sleeping_time():
time.sleep(60)
return


def wait_inbetween_calls() -> None:
wait_time = max(0, random.gauss(mu = 120, sigma = 30))
print(f"Waiting for extra time inbetween retriving tweets. ({wait_time:.3f}s)")
print(
"Waiting for extra time inbetween retriving tweets."
+ f" ({wait_time:.3f}s)"
)
time.sleep(wait_time)
go_to_bed()
return


def wait_inbetween_downloads():
wait_time = max(0, random.gauss(mu = 120, sigma = 30))
print(f"Waiting for extra time inbetween downloading media. ({wait_time:.3f}s)")
print(
"Waiting for extra time inbetween downloading media."
+ f" ({wait_time:.3f}s)"
)
time.sleep(wait_time)
go_to_bed()
return
Expand Down
12 changes: 12 additions & 0 deletions run_tumblr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
# -*- coding:utf-8 -*-

# --- 80 cols ---------------------------------------------------------------- #

python3 begin.py \
"https://www.tumblr.com/${1}" \
--cookies "cookies.txt" \
;

# END OF LINE

0 comments on commit 2bcf1d1

Please sign in to comment.