Skip to content

Commit

Permalink
Removed pytz (use own CET/UTC timezones)
Browse files Browse the repository at this point in the history
  • Loading branch information
adw0rd committed Dec 23, 2020
1 parent ba62b5e commit 1e257d7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
4 changes: 2 additions & 2 deletions instagrapi/mixins/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import base64
import time
import uuid
import pytz
import hmac
import hashlib
import random
Expand All @@ -12,6 +11,7 @@

from instagrapi import config
from instagrapi.exceptions import ReloginAttemptExceeded
from instagrapi.zones import CET


class PreLoginFlowMixin:
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 17 additions & 0 deletions instagrapi/zones.py
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@

setup(
name='instagrapi',
version='1.3.3',
version='1.3.4',
author='Mikhail Andreev',
author_email='[email protected]',
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',
Expand Down
12 changes: 6 additions & 6 deletions tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import json
import pytz
import random
import os.path
import unittest
Expand All @@ -14,6 +13,7 @@
DirectThread, DirectMessage, Usertag, Location, Account,
Hashtag
)
from instagrapi.zones import UTC


ACCOUNT_USERNAME = os.environ.get("IG_USERNAME", "instagrapi2")
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand All @@ -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)
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 1e257d7

Please sign in to comment.