1
Fork 0
mirror of https://github.com/thegeneralist01/twitter-openapi synced 2026-01-09 14:50:25 +01:00

update docs test

Signed-off-by: ふぁ <yuki@yuki0311.com>
This commit is contained in:
ふぁ 2023-07-31 17:59:02 +09:00
parent f5bcb8a9f7
commit 49b7951ba3
No known key found for this signature in database
GPG key ID: 83A8A5E74872A8AA
3 changed files with 33 additions and 14 deletions

View file

@ -94,4 +94,4 @@ jobs:
TWITTER_SESSION: ${{ secrets.TWITTER_SESSION }}
ERROR_UNCATCHED: "False"
SLEEP_TIME: 2
CUESOR_TEST_COUNT: 10
CUESOR_TEST_COUNT: 5

View file

@ -4,10 +4,8 @@
- `dist` Do not rewrite this file as it is an automatically generated OpenAPI file.
- `dist` Do not include this in the pull request due to potential conflicts.
I'm using openapi-generator with a dart-dio build.
It is desirable to pass these tests.
Untested pull requests are welcome, as Dart's development population is very small.
<https://github.com/fa0311/twitter_openapi_dart/tree/main/twitter_openapi_dart/test>
Users using vscode can build and test with the GUI.
[.vscode/launch.json](.vscode/launch.json) is a configuration file for vscode.
## Good first issues

View file

@ -11,6 +11,7 @@ import time
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s %(levelname)s %(message)s")
logger = logging.getLogger("test_serialize")
TWITTER_SESSION = os.environ.get("TWITTER_SESSION", None)
ERROR_UNCATCHED = os.environ.get("ERROR_UNCATCHED", "false").lower() == "true"
SLEEP_TIME = float(os.environ.get("SLEEP", "0"))
CUESOR_TEST_COUNT = int(os.environ.get("CUESOR_TEST_COUNT", "3"))
@ -19,9 +20,12 @@ CUESOR_TEST_COUNT = int(os.environ.get("CUESOR_TEST_COUNT", "3"))
if Path("cookie.json").exists():
with open("cookie.json", "r") as f:
cookies = json.load(f)
else:
data = base64.b64decode(os.environ["TWITTER_SESSION"]).decode("utf-8")
elif TWITTER_SESSION is not None:
data = base64.b64decode(TWITTER_SESSION).decode("utf-8")
cookies = json.loads(data)
else:
commands = ["python -m pip install tweepy_authlib", "python tools/login.py"]
raise Exception(f'cookie.json not found. Please run `{"; ".join(commands)}` first.')
cookies_str = "; ".join([f"{k}={v}" for k, v in cookies.items()])
@ -35,20 +39,31 @@ def get_key(snake_str):
return "".join(x.title() for x in components[1:])
def get_cursor(obj):
def get_cursor(obj, fn):
res = []
if type(obj) == dict:
if obj.get("__typename") is pt.TypeName.TIMELINETIMELINECURSOR:
res.append(obj["value"])
callback = fn(obj)
if callback is not None:
res.extend(callback)
else:
for v in obj.values():
res.extend(get_cursor(v))
res.extend(get_cursor(v, fn))
elif type(obj) == list:
for v in obj:
res.extend(get_cursor(v))
res.extend(get_cursor(v, fn))
return res
def find_cursor(x):
if x.get("__typename") is pt.TypeName.TIMELINETIMELINECURSOR:
return [x["value"]]
def find_name(x):
if x.get("name") is not None:
return [x["name"]]
def get_kwargs(key, additional):
kwargs = {"path_query_id": placeholder[key]["queryId"]}
if placeholder[key].get("variables") is not None:
@ -94,9 +109,15 @@ for x in [pt.DefaultApi, pt.TweetApi, pt.UserApi, pt.UserListApi]:
logger.info(f"Try: {key} {cursor}")
kwargs = get_kwargs(key, {} if cursor is None else {"cursor": cursor})
res: BaseModel = getattr(x(api_client), props)(**kwargs)
res: dict = getattr(x(api_client), props)(**kwargs).to_dict()
cursor_list.update(set(get_cursor(res.to_dict())) - cursor_history)
new_cursor = set(get_cursor(res, find_cursor)) - cursor_history
cursor_list.update(new_cursor)
# logger.info(f"Find cursor: {len(new_cursor)}")
if res.get("errors") is not None:
logger.error(res)
error_count += 1
if len(cursor_list) == 0:
break