From 1e257d72da9e78270c59731c1f744e00a8deb44c Mon Sep 17 00:00:00 2001 From: "Mikhail Andreev (adw0rd)" Date: Thu, 24 Dec 2020 00:06:19 +0300 Subject: [PATCH] Removed pytz (use own CET/UTC timezones) --- instagrapi/mixins/auth.py | 4 ++-- instagrapi/zones.py | 17 +++++++++++++++++ setup.py | 3 +-- tests.py | 12 ++++++------ 4 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 instagrapi/zones.py diff --git a/instagrapi/mixins/auth.py b/instagrapi/mixins/auth.py index 99cf593c..e42a5599 100644 --- a/instagrapi/mixins/auth.py +++ b/instagrapi/mixins/auth.py @@ -3,7 +3,6 @@ import base64 import time import uuid -import pytz import hmac import hashlib import random @@ -12,6 +11,7 @@ from instagrapi import config from instagrapi.exceptions import ReloginAttemptExceeded +from instagrapi.zones import CET class PreLoginFlowMixin: @@ -104,7 +104,7 @@ def get_timeline_feed(self, options: list = []) -> dict: "feed_view_info": "", "phone_id": self.phone_id, "battery_level": random.randint(25, 100), - "timezone_offset": datetime.datetime.now(pytz.timezone("CET")).strftime( + "timezone_offset": datetime.datetime.now(CET()).strftime( "%z" ), "_csrftoken": self.token, diff --git a/instagrapi/zones.py b/instagrapi/zones.py new file mode 100644 index 00000000..f92ad60e --- /dev/null +++ b/instagrapi/zones.py @@ -0,0 +1,17 @@ +from datetime import tzinfo, timedelta + + +class CET(tzinfo): + def utcoffset(self, dt): + return timedelta(hours=1) + + def dst(self, dt): + return timedelta(hours=2) + + +class UTC(tzinfo): + def utcoffset(self, dt): + return timedelta(0) + + def dst(self, dt): + return timedelta(0) diff --git a/setup.py b/setup.py index 5d6b8533..ea35a70a 100644 --- a/setup.py +++ b/setup.py @@ -19,13 +19,12 @@ setup( name='instagrapi', - version='1.3.3', + version='1.3.4', author='Mikhail Andreev', author_email='x11org@gmail.com', license='MIT', url='https://github.com/adw0rd/instagrapi', install_requires=[ - 'pytz==2020.1', 'requests==2.24.0', 'PySocks==1.7.1', 'Pillow==7.2.0', diff --git a/tests.py b/tests.py index 7464543e..e4c5b3ce 100644 --- a/tests.py +++ b/tests.py @@ -1,6 +1,5 @@ import os import json -import pytz import random import os.path import unittest @@ -14,6 +13,7 @@ DirectThread, DirectMessage, Usertag, Location, Account, Hashtag ) +from instagrapi.zones import UTC ACCOUNT_USERNAME = os.environ.get("IG_USERNAME", "instagrapi2") @@ -403,7 +403,7 @@ def test_media_comments(self): def test_media_comment(self): text = "Test text [%s]" % datetime.now().strftime("%s") - now = datetime.now(tz=pytz.UTC) + now = datetime.now(tz=UTC()) comment = self.api.media_comment(2276404890775267248, text) self.assertIsInstance(comment, Comment) comment = comment.dict() @@ -536,7 +536,7 @@ def test_extract_media_photo(self): "pk": 2154602296692269830, "code": "B3mr1-OlWMG", "media_type": 1, - "taken_at": datetime(2019, 10, 14, 15, 57, 10, tzinfo=pytz.UTC) + "taken_at": datetime(2019, 10, 14, 15, 57, 10, tzinfo=UTC()) }.items(): if isinstance(val, str): self.assertTrue(getattr(media, key).startswith(val)) @@ -562,7 +562,7 @@ def test_extract_media_video(self): "video_url": "https://", "thumbnail_url": "https://", "media_type": 2, - "taken_at": datetime(2018, 3, 13, 14, 59, 23, tzinfo=pytz.UTC) + "taken_at": datetime(2018, 3, 13, 14, 59, 23, tzinfo=UTC()) }.items(): if isinstance(val, str): self.assertTrue(getattr(media, key).startswith(val)) @@ -587,7 +587,7 @@ def test_extract_media_album(self): "pk": 1787135824035452364, "code": "BjNLpA1AhXM", "media_type": 8, - "taken_at": datetime(2018, 5, 25, 15, 46, 53, tzinfo=pytz.UTC), + "taken_at": datetime(2018, 5, 25, 15, 46, 53, tzinfo=UTC()), "product_type": "", }.items(): self.assertEqual(getattr(media, key), val) @@ -632,7 +632,7 @@ def test_extract_media_igtv(self): "thumbnail_url": "https://", "code": "ByYn5ZNlHWf", "media_type": 2, - "taken_at": datetime(2019, 6, 6, 22, 22, 6, tzinfo=pytz.UTC), + "taken_at": datetime(2019, 6, 6, 22, 22, 6, tzinfo=UTC()), "product_type": "igtv", }.items(): if isinstance(val, str):