diff --git a/src/resolver/dns.py b/src/resolver/dns.py new file mode 100644 index 0000000..daebd7b --- /dev/null +++ b/src/resolver/dns.py @@ -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 diff --git a/src/resolver/facebook.py b/src/resolver/facebook.py new file mode 100644 index 0000000..a4373d9 --- /dev/null +++ b/src/resolver/facebook.py @@ -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 diff --git a/src/resolver/fetch.py b/src/resolver/fetch.py index df13f5a..4f3c470 100644 --- a/src/resolver/fetch.py +++ b/src/resolver/fetch.py @@ -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: ''' @@ -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 @@ -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) @@ -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}") diff --git a/src/resolver/github.py b/src/resolver/github.py new file mode 100644 index 0000000..27791c1 --- /dev/null +++ b/src/resolver/github.py @@ -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 diff --git a/src/resolver/keybase.py b/src/resolver/keybase.py new file mode 100644 index 0000000..f701c2f --- /dev/null +++ b/src/resolver/keybase.py @@ -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 diff --git a/src/resolver/nextid.py b/src/resolver/nextid.py new file mode 100644 index 0000000..e85df1b --- /dev/null +++ b/src/resolver/nextid.py @@ -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 diff --git a/src/resolver/reddit.py b/src/resolver/reddit.py new file mode 100644 index 0000000..2e8b973 --- /dev/null +++ b/src/resolver/reddit.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +''' +Author: Zella Zhong +Date: 2024-11-06 01:22:19 +LastEditors: Zella Zhong +LastEditTime: 2024-11-06 01:26:42 +FilePath: /data_service/src/resolver/reddit.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_reddit(info, handle): + primary_id = f"{Platform.reddit.value},{handle}" + aliases = [primary_id] + identity_record = IdentityRecord( + id=primary_id, + aliases=aliases, + identity=handle, + platform=Platform.reddit, + network=None, + primary_name=None, + is_primary=False, + profile=None + ) + return identity_record + +async def query_profile_by_reddit_handles(info, handles): + if len(handles) > QUERY_MAX_LIMIT: + return ExceedRangeInput(QUERY_MAX_LIMIT) + + result = [] + for handle in handles: + primary_id = f"{Platform.reddit.value},{handle}" + aliases = [primary_id] + result.append(IdentityRecordSimplified( + id=primary_id, + aliases=aliases, + identity=handle, + platform=Platform.reddit, + network=None, + primary_name=None, + is_primary=False, + profile=None + )) + + return result diff --git a/src/resolver/twitter.py b/src/resolver/twitter.py new file mode 100644 index 0000000..dfb8f3c --- /dev/null +++ b/src/resolver/twitter.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +''' +Author: Zella Zhong +Date: 2024-11-06 01:21:20 +LastEditors: Zella Zhong +LastEditTime: 2024-11-06 01:26:02 +FilePath: /data_service/src/resolver/twitter.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_twitter(info, handle): + primary_id = f"{Platform.twitter.value},{handle}" + aliases = [primary_id] + identity_record = IdentityRecord( + id=primary_id, + aliases=aliases, + identity=handle, + platform=Platform.twitter, + network=None, + primary_name=None, + is_primary=False, + profile=None + ) + return identity_record + +async def query_profile_by_twitter_handles(info, handles): + if len(handles) > QUERY_MAX_LIMIT: + return ExceedRangeInput(QUERY_MAX_LIMIT) + + result = [] + for handle in handles: + primary_id = f"{Platform.twitter.value},{handle}" + aliases = [primary_id] + result.append(IdentityRecordSimplified( + id=primary_id, + aliases=aliases, + identity=handle, + platform=Platform.twitter, + network=None, + primary_name=None, + is_primary=False, + profile=None + )) + + return result diff --git a/src/scalar/platform.py b/src/scalar/platform.py index 2a88268..43b64d7 100644 --- a/src/scalar/platform.py +++ b/src/scalar/platform.py @@ -4,7 +4,7 @@ Author: Zella Zhong Date: 2024-10-06 17:45:51 LastEditors: Zella Zhong -LastEditTime: 2024-10-24 17:34:34 +LastEditTime: 2024-11-06 01:24:23 FilePath: /data_service/src/scalar/platform.py Description: ''' @@ -34,3 +34,11 @@ class Platform(Enum): ton = "ton" xrpc = "xrpc" cosmos = "cosmos" + + twitter = "twitter" + github = "github" + reddit = "reddit" + nextid = "nextid" + keybase = "keybase" + facebook = "facebook" + dns = "dns"