Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#] add nextid, keybase contains platform #7

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions src/resolver/dns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
Author: Zella Zhong
Date: 2024-11-06 01:22:27
LastEditors: Zella Zhong
LastEditTime: 2024-11-06 01:27:45
FilePath: /data_service/src/resolver/dns.py
Description:
'''
import logging
from datetime import datetime
from sqlalchemy.inspection import inspect
from sqlalchemy import select, update, and_, or_
from sqlalchemy.orm import load_only
from urllib.parse import unquote

from session import get_session
from model import EnsnameModel

from utils import check_evm_address, convert_camel_case

from scalar.platform import Platform
from scalar.network import Network
from scalar.identity_graph import IdentityRecordSimplified
from scalar.identity_record import IdentityRecord
from scalar.profile import Profile
from scalar.error import EmptyInput, EvmAddressInvalid, ExceedRangeInput

QUERY_MAX_LIMIT = 200

async def query_profile_by_single_dns(info, handle):
primary_id = f"{Platform.dns.value},{handle}"
aliases = [primary_id]
identity_record = IdentityRecord(
id=primary_id,
aliases=aliases,
identity=handle,
platform=Platform.dns,
network=None,
primary_name=None,
is_primary=False,
profile=None
)
return identity_record

async def query_profile_by_dns_handles(info, handles):
if len(handles) > QUERY_MAX_LIMIT:
return ExceedRangeInput(QUERY_MAX_LIMIT)

result = []
for handle in handles:
primary_id = f"{Platform.dns.value},{handle}"
aliases = [primary_id]
result.append(IdentityRecordSimplified(
id=primary_id,
aliases=aliases,
identity=handle,
platform=Platform.dns,
network=None,
primary_name=None,
is_primary=False,
profile=None
))

return result
66 changes: 66 additions & 0 deletions src/resolver/facebook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
Author: Zella Zhong
Date: 2024-11-06 01:22:35
LastEditors: Zella Zhong
LastEditTime: 2024-11-06 01:27:30
FilePath: /data_service/src/resolver/facebook.py
Description:
'''
import logging
from datetime import datetime
from sqlalchemy.inspection import inspect
from sqlalchemy import select, update, and_, or_
from sqlalchemy.orm import load_only
from urllib.parse import unquote

from session import get_session
from model import EnsnameModel

from utils import check_evm_address, convert_camel_case

from scalar.platform import Platform
from scalar.network import Network
from scalar.identity_graph import IdentityRecordSimplified
from scalar.identity_record import IdentityRecord
from scalar.profile import Profile
from scalar.error import EmptyInput, EvmAddressInvalid, ExceedRangeInput

QUERY_MAX_LIMIT = 200

async def query_profile_by_single_facebook(info, handle):
primary_id = f"{Platform.facebook.value},{handle}"
aliases = [primary_id]
identity_record = IdentityRecord(
id=primary_id,
aliases=aliases,
identity=handle,
platform=Platform.facebook,
network=None,
primary_name=None,
is_primary=False,
profile=None
)
return identity_record

async def query_profile_by_facebook_handles(info, handles):
if len(handles) > QUERY_MAX_LIMIT:
return ExceedRangeInput(QUERY_MAX_LIMIT)

result = []
for handle in handles:
primary_id = f"{Platform.facebook.value},{handle}"
aliases = [primary_id]
result.append(IdentityRecordSimplified(
id=primary_id,
aliases=aliases,
identity=handle,
platform=Platform.facebook,
network=None,
primary_name=None,
is_primary=False,
profile=None
))

return result
37 changes: 36 additions & 1 deletion src/resolver/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Author: Zella Zhong
Date: 2024-10-06 19:05:41
LastEditors: Zella Zhong
LastEditTime: 2024-11-05 00:19:05
LastEditTime: 2024-11-06 01:40:17
FilePath: /data_service/src/resolver/fetch.py
Description:
'''
Expand Down Expand Up @@ -34,6 +34,13 @@
from resolver.xrpc import query_profile_by_xrpc_addresses, query_profile_by_single_xrpc
from resolver.cosmos import query_profile_by_cosmos_addresses, query_profile_by_single_cosmos

from resolver.twitter import query_profile_by_single_twitter, query_profile_by_twitter_handles
from resolver.github import query_profile_by_single_github, query_profile_by_github_handles
from resolver.reddit import query_profile_by_single_reddit, query_profile_by_reddit_handles
from resolver.dns import query_profile_by_single_dns, query_profile_by_dns_handles
from resolver.facebook import query_profile_by_single_facebook, query_profile_by_facebook_handles
from resolver.keybase import query_profile_by_single_keybase, query_profile_by_keybase_handles
from resolver.nextid import query_profile_by_single_nextid, query_profile_by_nextid_handles

from resolver.farcaster import query_farcaster_profile_by_ids_cache
from resolver.lens import query_lens_profile_by_ids_cache
Expand Down Expand Up @@ -87,6 +94,20 @@ async def single_fetch(info, platform, identity):
return await query_profile_by_single_xrpc(info, identity)
elif platform == Platform.cosmos:
return await query_profile_by_single_cosmos(info, identity)
elif platform == Platform.twitter:
return await query_profile_by_single_twitter(info, identity)
elif platform == Platform.github:
return await query_profile_by_single_github(info, identity)
elif platform == Platform.reddit:
return await query_profile_by_single_reddit(info, identity)
elif platform == Platform.dns:
return await query_profile_by_single_dns(info, identity)
elif platform == Platform.facebook:
return await query_profile_by_single_facebook(info, identity)
elif platform == Platform.keybase:
return await query_profile_by_single_keybase(info, identity)
elif platform == Platform.nextid:
return await query_profile_by_single_nextid(info, identity)
else:
return PlatformNotSupport(platform)

Expand Down Expand Up @@ -268,6 +289,20 @@ async def batch_fetch_all(info, vertices_map):
tasks.append(query_profile_by_xrpc_addresses(info, identities))
elif platform_enum == Platform.cosmos:
tasks.append(query_profile_by_cosmos_addresses(info, identities))
elif platform == Platform.twitter:
tasks.append(query_profile_by_twitter_handles(info, identities))
elif platform == Platform.github:
tasks.append(query_profile_by_github_handles(info, identities))
elif platform == Platform.reddit:
tasks.append(query_profile_by_reddit_handles(info, identities))
elif platform == Platform.dns:
tasks.append(query_profile_by_dns_handles(info, identities))
elif platform == Platform.facebook:
tasks.append(query_profile_by_facebook_handles(info, identities))
elif platform == Platform.keybase:
tasks.append(query_profile_by_keybase_handles(info, identities))
elif platform == Platform.nextid:
tasks.append(query_profile_by_nextid_handles(info, identities))
else:
logging.warning(f"Unsupported platform: {platform}")

Expand Down
66 changes: 66 additions & 0 deletions src/resolver/github.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
Author: Zella Zhong
Date: 2024-11-06 01:21:32
LastEditors: Zella Zhong
LastEditTime: 2024-11-06 01:27:17
FilePath: /data_service/src/resolver/github.py
Description:
'''
import logging
from datetime import datetime
from sqlalchemy.inspection import inspect
from sqlalchemy import select, update, and_, or_
from sqlalchemy.orm import load_only
from urllib.parse import unquote

from session import get_session
from model import EnsnameModel

from utils import check_evm_address, convert_camel_case

from scalar.platform import Platform
from scalar.network import Network
from scalar.identity_graph import IdentityRecordSimplified
from scalar.identity_record import IdentityRecord
from scalar.profile import Profile
from scalar.error import EmptyInput, EvmAddressInvalid, ExceedRangeInput

QUERY_MAX_LIMIT = 200

async def query_profile_by_single_github(info, handle):
primary_id = f"{Platform.github.value},{handle}"
aliases = [primary_id]
identity_record = IdentityRecord(
id=primary_id,
aliases=aliases,
identity=handle,
platform=Platform.github,
network=None,
primary_name=None,
is_primary=False,
profile=None
)
return identity_record

async def query_profile_by_github_handles(info, handles):
if len(handles) > QUERY_MAX_LIMIT:
return ExceedRangeInput(QUERY_MAX_LIMIT)

result = []
for handle in handles:
primary_id = f"{Platform.github.value},{handle}"
aliases = [primary_id]
result.append(IdentityRecordSimplified(
id=primary_id,
aliases=aliases,
identity=handle,
platform=Platform.github,
network=None,
primary_name=None,
is_primary=False,
profile=None
))

return result
66 changes: 66 additions & 0 deletions src/resolver/keybase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
Author: Zella Zhong
Date: 2024-11-06 01:21:48
LastEditors: Zella Zhong
LastEditTime: 2024-11-06 01:28:41
FilePath: /data_service/src/resolver/keybase.py
Description:
'''
import logging
from datetime import datetime
from sqlalchemy.inspection import inspect
from sqlalchemy import select, update, and_, or_
from sqlalchemy.orm import load_only
from urllib.parse import unquote

from session import get_session
from model import EnsnameModel

from utils import check_evm_address, convert_camel_case

from scalar.platform import Platform
from scalar.network import Network
from scalar.identity_graph import IdentityRecordSimplified
from scalar.identity_record import IdentityRecord
from scalar.profile import Profile
from scalar.error import EmptyInput, EvmAddressInvalid, ExceedRangeInput

QUERY_MAX_LIMIT = 200

async def query_profile_by_single_keybase(info, keybase_username):
primary_id = f"{Platform.keybase.value},{keybase_username}"
aliases = [primary_id]
identity_record = IdentityRecord(
id=primary_id,
aliases=aliases,
identity=keybase_username,
platform=Platform.keybase,
network=None,
primary_name=None,
is_primary=False,
profile=None
)
return identity_record

async def query_profile_by_keybase_handles(info, keybase_usernames):
if len(keybase_usernames) > QUERY_MAX_LIMIT:
return ExceedRangeInput(QUERY_MAX_LIMIT)

result = []
for keybase_username in keybase_usernames:
primary_id = f"{Platform.keybase.value},{keybase_username}"
aliases = [primary_id]
result.append(IdentityRecordSimplified(
id=primary_id,
aliases=aliases,
identity=keybase_username,
platform=Platform.keybase,
network=None,
primary_name=None,
is_primary=False,
profile=None
))

return result
66 changes: 66 additions & 0 deletions src/resolver/nextid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
Author: Zella Zhong
Date: 2024-11-06 01:21:42
LastEditors: Zella Zhong
LastEditTime: 2024-11-06 01:28:07
FilePath: /data_service/src/resolver/nextid.py
Description:
'''
import logging
from datetime import datetime
from sqlalchemy.inspection import inspect
from sqlalchemy import select, update, and_, or_
from sqlalchemy.orm import load_only
from urllib.parse import unquote

from session import get_session
from model import EnsnameModel

from utils import check_evm_address, convert_camel_case

from scalar.platform import Platform
from scalar.network import Network
from scalar.identity_graph import IdentityRecordSimplified
from scalar.identity_record import IdentityRecord
from scalar.profile import Profile
from scalar.error import EmptyInput, EvmAddressInvalid, ExceedRangeInput

QUERY_MAX_LIMIT = 200

async def query_profile_by_single_nextid(info, persona):
primary_id = f"{Platform.nextid.value},{persona}"
aliases = [primary_id]
identity_record = IdentityRecord(
id=primary_id,
aliases=aliases,
identity=persona,
platform=Platform.nextid,
network=None,
primary_name=None,
is_primary=False,
profile=None
)
return identity_record

async def query_profile_by_nextid_handles(info, personas):
if len(personas) > QUERY_MAX_LIMIT:
return ExceedRangeInput(QUERY_MAX_LIMIT)

result = []
for persona in personas:
primary_id = f"{Platform.nextid.value},{persona}"
aliases = [primary_id]
result.append(IdentityRecordSimplified(
id=primary_id,
aliases=aliases,
identity=persona,
platform=Platform.nextid,
network=None,
primary_name=None,
is_primary=False,
profile=None
))

return result
Loading
Loading