Skip to content

Commit 1e257d7

Browse files
committed
Removed pytz (use own CET/UTC timezones)
1 parent ba62b5e commit 1e257d7

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

instagrapi/mixins/auth.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import base64
44
import time
55
import uuid
6-
import pytz
76
import hmac
87
import hashlib
98
import random
@@ -12,6 +11,7 @@
1211

1312
from instagrapi import config
1413
from instagrapi.exceptions import ReloginAttemptExceeded
14+
from instagrapi.zones import CET
1515

1616

1717
class PreLoginFlowMixin:
@@ -104,7 +104,7 @@ def get_timeline_feed(self, options: list = []) -> dict:
104104
"feed_view_info": "",
105105
"phone_id": self.phone_id,
106106
"battery_level": random.randint(25, 100),
107-
"timezone_offset": datetime.datetime.now(pytz.timezone("CET")).strftime(
107+
"timezone_offset": datetime.datetime.now(CET()).strftime(
108108
"%z"
109109
),
110110
"_csrftoken": self.token,

instagrapi/zones.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from datetime import tzinfo, timedelta
2+
3+
4+
class CET(tzinfo):
5+
def utcoffset(self, dt):
6+
return timedelta(hours=1)
7+
8+
def dst(self, dt):
9+
return timedelta(hours=2)
10+
11+
12+
class UTC(tzinfo):
13+
def utcoffset(self, dt):
14+
return timedelta(0)
15+
16+
def dst(self, dt):
17+
return timedelta(0)

setup.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@
1919

2020
setup(
2121
name='instagrapi',
22-
version='1.3.3',
22+
version='1.3.4',
2323
author='Mikhail Andreev',
2424
author_email='[email protected]',
2525
license='MIT',
2626
url='https://github.com/adw0rd/instagrapi',
2727
install_requires=[
28-
'pytz==2020.1',
2928
'requests==2.24.0',
3029
'PySocks==1.7.1',
3130
'Pillow==7.2.0',

tests.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
import json
3-
import pytz
43
import random
54
import os.path
65
import unittest
@@ -14,6 +13,7 @@
1413
DirectThread, DirectMessage, Usertag, Location, Account,
1514
Hashtag
1615
)
16+
from instagrapi.zones import UTC
1717

1818

1919
ACCOUNT_USERNAME = os.environ.get("IG_USERNAME", "instagrapi2")
@@ -403,7 +403,7 @@ def test_media_comments(self):
403403

404404
def test_media_comment(self):
405405
text = "Test text [%s]" % datetime.now().strftime("%s")
406-
now = datetime.now(tz=pytz.UTC)
406+
now = datetime.now(tz=UTC())
407407
comment = self.api.media_comment(2276404890775267248, text)
408408
self.assertIsInstance(comment, Comment)
409409
comment = comment.dict()
@@ -536,7 +536,7 @@ def test_extract_media_photo(self):
536536
"pk": 2154602296692269830,
537537
"code": "B3mr1-OlWMG",
538538
"media_type": 1,
539-
"taken_at": datetime(2019, 10, 14, 15, 57, 10, tzinfo=pytz.UTC)
539+
"taken_at": datetime(2019, 10, 14, 15, 57, 10, tzinfo=UTC())
540540
}.items():
541541
if isinstance(val, str):
542542
self.assertTrue(getattr(media, key).startswith(val))
@@ -562,7 +562,7 @@ def test_extract_media_video(self):
562562
"video_url": "https://",
563563
"thumbnail_url": "https://",
564564
"media_type": 2,
565-
"taken_at": datetime(2018, 3, 13, 14, 59, 23, tzinfo=pytz.UTC)
565+
"taken_at": datetime(2018, 3, 13, 14, 59, 23, tzinfo=UTC())
566566
}.items():
567567
if isinstance(val, str):
568568
self.assertTrue(getattr(media, key).startswith(val))
@@ -587,7 +587,7 @@ def test_extract_media_album(self):
587587
"pk": 1787135824035452364,
588588
"code": "BjNLpA1AhXM",
589589
"media_type": 8,
590-
"taken_at": datetime(2018, 5, 25, 15, 46, 53, tzinfo=pytz.UTC),
590+
"taken_at": datetime(2018, 5, 25, 15, 46, 53, tzinfo=UTC()),
591591
"product_type": "",
592592
}.items():
593593
self.assertEqual(getattr(media, key), val)
@@ -632,7 +632,7 @@ def test_extract_media_igtv(self):
632632
"thumbnail_url": "https://",
633633
"code": "ByYn5ZNlHWf",
634634
"media_type": 2,
635-
"taken_at": datetime(2019, 6, 6, 22, 22, 6, tzinfo=pytz.UTC),
635+
"taken_at": datetime(2019, 6, 6, 22, 22, 6, tzinfo=UTC()),
636636
"product_type": "igtv",
637637
}.items():
638638
if isinstance(val, str):

0 commit comments

Comments
 (0)