1
Fork 0
mirror of https://github.com/thegeneralist01/twitter-openapi synced 2026-01-11 15:40:26 +01:00

Merge pull request #51 from fa0311/dev

Dev
This commit is contained in:
ふぁ 2024-02-06 15:08:09 +09:00 committed by GitHub
commit 68def8cc73
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 51 additions and 36 deletions

View file

@ -39,7 +39,7 @@ jobs:
- name: Get Openapi Generator
run: |
wget https://github.com/fa0311/openapi-generator/releases/download/twitter_openapi_python_1.3.0/openapi-generator-cli.jar -O openapi-generator-cli.jar --no-verbose
wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.2.0/openapi-generator-cli-7.2.0.jar -O openapi-generator-cli.jar --no-verbose
if: steps.openapi-generator-cache.outputs.cache-hit != 'true'
# Python Setup

View file

@ -40,7 +40,7 @@ jobs:
- name: Get Openapi Generator
run: |
wget https://github.com/fa0311/openapi-generator/releases/download/twitter_openapi_python_1.3.0/openapi-generator-cli.jar -O openapi-generator-cli.jar --no-verbose
wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.2.0/openapi-generator-cli-7.2.0.jar -O openapi-generator-cli.jar --no-verbose
if: steps.openapi-generator-cache.outputs.cache-hit != 'true'
# Python Setup

View file

@ -1,3 +1,9 @@
{
"recommendations": ["redhat.vscode-yaml"]
}
"recommendations": [
"redhat.vscode-yaml",
"ms-python.vscode-pylance",
"ms-python.python",
"ms-python.debugpy",
"charliermarsh.ruff"
]
}

8
.vscode/launch.json vendored
View file

@ -3,7 +3,7 @@
"configurations": [
{
"name": "Python: 現在のファイル",
"type": "python",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
@ -11,7 +11,7 @@
},
{
"name": "build",
"type": "python",
"type": "debugpy",
"request": "launch",
"program": "tools/build.py",
"console": "integratedTerminal",
@ -19,7 +19,7 @@
},
{
"name": "test",
"type": "python",
"type": "debugpy",
"request": "launch",
"program": "test/python/test_serialize.py",
"console": "integratedTerminal",
@ -30,4 +30,4 @@
}
}
]
}
}

12
.vscode/settings.json vendored
View file

@ -5,5 +5,15 @@
"yaml.hover": true,
"yaml.schemas": {
"https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.0/schema.json": "src/**/*.yaml"
},
"[yaml]": {
"editor.defaultFormatter": "redhat.vscode-yaml"
},
// "python.analysis.typeCheckingMode": "basic",
"[python]": {
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit",
"source.fixAll": "explicit",
},
}
}
}

7
.vscode/tasks.json vendored
View file

@ -17,6 +17,7 @@
"command": [
".venv/Scripts/activate;",
"python tools/build.py;",
"scoop reset temurin11-jdk;",
"java -jar openapi-generator-cli.jar generate -c test/python/openapi-generator-config.yaml -g python;",
"python test/python/replace.py;",
"python -m pip install ./python_generated;"
@ -33,16 +34,16 @@
"command": [
"python3 -m venv .venv;",
".venv/bin/python3 -m pip install -r requirements.txt;",
"wget https://github.com/fa0311/openapi-generator/releases/download/twitter_openapi_python_1.3.0/openapi-generator-cli.jar -O openapi-generator-cli.jar;"
"wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.2.0/openapi-generator-cli-7.2.0.jar -O openapi-generator-cli.jar;"
]
},
"windows": {
"command": [
"python -m venv .venv;",
".venv/Scripts/python -m pip install -r requirements.txt;",
"Invoke-WebRequest https://github.com/fa0311/openapi-generator/releases/download/twitter_openapi_python_1.3.0/openapi-generator-cli.jar -OutFile openapi-generator-cli.jar;"
"Invoke-WebRequest https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.2.0/openapi-generator-cli-7.2.0.jar -OutFile openapi-generator-cli.jar;"
]
}
}
]
}
}

View file

@ -759,7 +759,6 @@ components:
itemContent:
$ref: '#/components/schemas/ItemContentUnion'
required:
- clientEventInfo
- itemContent
ModuleItem:
properties:
@ -1270,6 +1269,7 @@ components:
enum:
- Vertical
- VerticalConversation
- VerticalGrid
- Carousel
type: string
entryType:

View file

@ -759,7 +759,6 @@ components:
itemContent:
$ref: '#/components/schemas/ItemContentUnion'
required:
- clientEventInfo
- itemContent
ModuleItem:
properties:
@ -1270,6 +1269,7 @@ components:
enum:
- Vertical
- VerticalConversation
- VerticalGrid
- Carousel
type: string
entryType:

View file

@ -60,7 +60,7 @@ components:
$ref: "#/components/schemas/ContentEntryType" # TimelineTimelineCursor
displayType:
type: string
enum: [Vertical, VerticalConversation, Carousel]
enum: [Vertical, VerticalConversation, VerticalGrid, Carousel]
items:
type: array
items:
@ -108,7 +108,6 @@ components:
ModuleEntry:
required:
- "clientEventInfo"
- "itemContent"
properties:
clientEventInfo:

View file

@ -1,15 +1,15 @@
import json
import os
import logging
import base64
import openapi_client as pt
from pathlib import Path
import time
import glob
import aenum
import concurrent.futures
import glob
import json
import logging
import os
import time
import traceback
from pathlib import Path
import aenum
import openapi_client as pt
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s %(levelname)s %(message)s")
logger = logging.getLogger("test_serialize")
@ -28,14 +28,14 @@ def get_key(snake_str):
def get_cursor(obj, fn):
res = []
if type(obj) == dict:
if isinstance(obj, dict):
callback = fn(obj)
if callback is not None:
res.extend(callback)
else:
for v in obj.values():
res.extend(get_cursor(v, fn))
elif type(obj) == list:
elif isinstance(obj, list):
for v in obj:
res.extend(get_cursor(v, fn))
return res
@ -77,9 +77,8 @@ def match_rate(a, b, key=""):
return 1
if a is False and b is None:
return 1
if type(a) != type(b):
return match_rate_zero(key)
if type(a) == dict and type(b) == dict:
if isinstance(a, list):
data = [match_rate(a[i], b[i], key=f"{key}[{i}]") for i in range(len(a))]
if len(a) == 0 and len(b) == 0:
return 1
if len(a) == 0 or len(b) == 0:
@ -88,16 +87,16 @@ def match_rate(a, b, key=""):
data = [match_rate(a.get(k), b.get(k), key=f"{key}.{k}") for k in a.keys()]
return sum(data) / len(a)
if type(a) == list and type(b) == list:
if isinstance(a, list) and isinstance(b, list):
if len(a) == 0 and len(b) == 0:
return 1
if len(a) != len(b):
return match_rate_zero(a, b, key=key)
return match_rate_zero(key)
data = [match_rate(a[i], b[i], key=f"{key}[{i}]") for i in range(len(a))]
return sum(data) / len(a)
if a == b:
return 1
return match_rate_zero(a, b, key=key)
return match_rate_zero(key)
def save_cache(data):
@ -114,7 +113,7 @@ def task_callback(file, thread=True):
data = pt.__dict__[cache["type"]].from_json(cache["raw"])
rate = match_rate(data.to_dict(), json.loads(cache["raw"]))
return rate, file
except Exception as e:
except Exception:
if thread:
return 0, file
else:
@ -205,7 +204,7 @@ if __name__ == "__main__":
save_cache(
{
"raw": res.raw_data,
"raw": res.raw_data.decode("utf-8"),
"type": res.data.__class__.__name__,
}
)
@ -229,7 +228,7 @@ if __name__ == "__main__":
error_count += 1
try:
logger.info(f"Try: Self UserByScreenName Test")
logger.info("Try: Self UserByScreenName Test")
kwargs = get_kwargs("UserByScreenName", {"screen_name": "a810810931931"})
res = pt.UserApi(api_client).get_user_by_screen_name_with_http_info(**kwargs)
data = res.data.to_dict()
@ -244,7 +243,7 @@ if __name__ == "__main__":
error_count += 1
try:
logger.info(f"Try: Self UserTweets Test")
logger.info("Try: Self UserTweets Test")
kwargs = get_kwargs("UserTweets", {"userId": "1180389371481976833"})
res = pt.TweetApi(api_client).get_user_tweets_with_http_info(**kwargs)
data = res.data.to_dict()