diff --git a/test_vx.py b/test_vx.py index 58bec41..e74f385 100644 --- a/test_vx.py +++ b/test_vx.py @@ -44,6 +44,15 @@ def compareDict(original,compare): else: compareDict(original[key],compare[key]) +## Specific API tests ## +def test_syndicationAPI(): + tweet = twExtract.extractStatus_syndication(testMediaTweet,workaroundTokens=tokens) + assert tweet["full_text"]==testMedia_compare['description'] + +def test_v2API(): + tweet = twExtract.extractStatusV2Legacy(testMediaTweet,workaroundTokens=tokens) + assert tweet["full_text"]==testMedia_compare['description'] + ## Tweet retrieve tests ## def test_textTweetExtract(): tweet = twExtract.extractStatus(testTextTweet,workaroundTokens=tokens) @@ -253,4 +262,7 @@ def test_combine(): resp = client.get(f"/rendercombined.jpg?imgs={img1},{img2}",headers={"User-Agent":"test"}) assert resp.status_code==200 assert resp.headers["Content-Type"]=="image/jpeg" - assert len(resp.data)>1000 \ No newline at end of file + assert len(resp.data)>1000 + +def test_calcSyndicationToken(): + assert twExtract.calcSyndicationToken("1691389765483200513") == "43lnobuxzql" \ No newline at end of file diff --git a/twExtract/__init__.py b/twExtract/__init__.py index dd97ebc..203fe26 100644 --- a/twExtract/__init__.py +++ b/twExtract/__init__.py @@ -5,6 +5,7 @@ import re import os import random import urllib.parse +import math bearer="Bearer AAAAAAAAAAAAAAAAAAAAAPYXBAAAAAAACLXUNDekMxqa8h%2F40K4moUkGsoc%3DTYfbDKbT3jJPCEVnMYqilB28NHfOPqkca3qaAxGfsyKCs0wRbw" v2Bearer="Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA" guestToken=None @@ -71,8 +72,33 @@ def extractStatus_guestToken(url): raise TwExtractError(error["code"], error["message"]) return output -def calcSyndicationToken(twID): - return 'x' # wip +digits = "0123456789abcdefghijklmnopqrstuvwxyz" + +def baseConversion(x, base): + result = '' + i = int(x) + while i > 0: + result = digits[i % base] + result + i = i // base + if int(x) != x: + result += '.' + i = x - int(x) + d = 0 + while i != int(i): + result += digits[int(i * base % base)] + i = i * base + d += 1 + if d >= 8: + break + return result + +def calcSyndicationToken(idStr): + id = int(idStr) / 1000000000000000 * math.pi + o = baseConversion(x=id, base=int(math.pow(6, 2))) + c = o.replace('0', '').replace('.', '') + if c == '': + c = '0' + return c def extractStatus_syndication(url,workaroundTokens=None): # https://github.com/mikf/gallery-dl/blob/46cae04aa3a113c7b6bbee1bb468669564b14ae8/gallery_dl/extractor/twitter.py#L1784