diff options
author | jwansek <eddie.atten.ea29@gmail.com> | 2023-08-07 17:12:05 +0100 |
---|---|---|
committer | jwansek <eddie.atten.ea29@gmail.com> | 2023-08-07 17:12:05 +0100 |
commit | 8932f0ca188092891f8798f77c0643cc69f6f29f (patch) | |
tree | 903bcba749522fd1979101e34f61ddee4bc8a877 | |
parent | 759ccd84ab78a5962172e8969d4084a53f8fb154 (diff) | |
download | yaoi-communism-8932f0ca188092891f8798f77c0643cc69f6f29f.tar.gz yaoi-communism-8932f0ca188092891f8798f77c0643cc69f6f29f.zip |
Changed to work with new twitter API, changed cron system
-rwxr-xr-x | Dockerfile | 18 | ||||
-rwxr-xr-x | bot.py | 32 | ||||
-rw-r--r-- | entrypoint.sh | 4 |
3 files changed, 38 insertions, 16 deletions
@@ -1,11 +1,15 @@ -FROM debian:latest -MAINTAINER Eden Attenborough "eddie.atten.ea29@gmail.com" -RUN apt-get update --allow-releaseinfo-change +FROM ubuntu:latest +MAINTAINER Eden Attenborough "eda@e.email" +ENV TZ=Europe/London +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone +RUN apt-get update -y RUN apt-get install -y tzdata python3-pip build-essential pkg-config cron libjpeg-dev zlib1g-dev libfreetype6-dev +RUN mkdir app COPY . /app WORKDIR /app -COPY crontab /etc/cron.d/oad-crontab -RUN chmod 0644 /etc/cron.d/oad-crontab && crontab /etc/cron.d/oad-crontab -ARG PIP_ONLY_BINARY=cmake +RUN touch .docker RUN pip3 install -r requirements.txt -ENTRYPOINT ["cron", "-f"] + +RUN echo "0 */3 * * * root python3 /app/bot.py > /proc/1/fd/1 2>/proc/1/fd/2" > /etc/crontab +ENTRYPOINT ["bash"] +CMD ["entrypoint.sh"] @@ -1,23 +1,37 @@ import os
-os.chdir("/app")
+os.chdir(os.path.dirname(__file__))
-from twython import Twython
import get_images
+import tweepy
-os.environ["SSL_CERT_DIR"] = "/etc/ssl/certs"
+def twitter_post(message, impath):
+ auth = tweepy.OAuth1UserHandler(
+ get_images.CONFIG["twitterapi"]["consumer_key"],
+ get_images.CONFIG["twitterapi"]["consumer_secret"],
+ get_images.CONFIG["twitterapi"]["access_token"],
+ get_images.CONFIG["twitterapi"]["access_token_secret"],
+ )
-twitter = Twython(*get_images.CONFIG["twitterapi"].values())
+ api = tweepy.API(auth)
+
+ media_upload = api.simple_upload(impath)
+ media_id = media_upload.media_id
+
+ client = tweepy.Client(
+ **get_images.CONFIG["twitterapi"]
+ )
+
+ response = client.create_tweet(text = message, media_ids = [media_id])
+ get_images.logging.info(str(response))
+ return response
def post():
images = get_images.main()
while images is None:
images = get_images.main()
- impath, source, text = images
- with open(impath, "rb") as img:
- response = twitter.upload_media(media = img)
- message = f"{text} ({source})"
- out = twitter.update_status(status=message, media_ids=[response["media_id"]])
+ impath, source, text = images
+ twitter_post("%s (%s)" % (text, source), impath)
get_images.logging.info("Posted to twitter.")
if __name__ == "__main__":
diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..610bf84 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,4 @@ +# https://stackoverflow.com/questions/27771781/how-can-i-access-docker-set-environment-variables-from-a-cron-job/35088810#35088810 +printenv | grep -v "no_proxy" >> /etc/environment + +cron -f
\ No newline at end of file |