Skip to content
This repository has been archived by the owner on Apr 28, 2024. It is now read-only.

Structure, Readme, Simplified API #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 0 additions & 2 deletions .gitattributes

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
connection.json
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Old YikYak API
Example to Query all yaks at a single location: `Test.py`

`connection.json` must be completed for the tests to run (CONTAINS API KEY FOR POSITION STACK AND YIKYAK)

i'm bad at writing docs -- no one will use this anyways.
10 changes: 10 additions & 0 deletions Test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from api_connectors.PositionStackAPI import PositionStackAPI #The API that can convert landmark / address to coordinate
from api_connectors.Interyak import QueryYaks # One File to contain all endpoints (simplicity)

Geocoder = PositionStackAPI.PositionStackAPI()

point = Geocoder.ForwardGeocode("College of Idaho")
data = QueryYaks(point).data

for d in data: print(d["voteCount"], d["text"])

33 changes: 33 additions & 0 deletions api_connectors/Interyak.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from YakConnection import AccessToken, Connection
import json, requests

class QueryYaks(Connection):
def __init__(self, Point=(0,0)):
super().__init__()
self.secret = AccessToken()
self.Point = Point
headers = {
'content-type': 'application/json',
'accept': '*/*',
'apollographql-client-version': '3.0.3-3',
'authorization': str(AccessToken()),
'accept-language': 'en-US,en;q=0.9',
'location': 'POINT(0 0)',
'x-apollo-operation-type': 'query',
'user-agent': 'Yik%20Yak/3 CFNetwork/1399 Darwin/22.1.0',
'apollographql-client-name': 'com.yikyak.2-apollo-ios',
'x-apollo-operation-name': 'Feed',
}
json_data = {
'operationName': 'Feed',
'query': 'query Feed($feedType: FeedType, $feedOrder: FeedOrder, $pageLimit: Int, $cursor: String, $point: FixedPointScalar) {\n feed(\n feedType: $feedType\n feedOrder: $feedOrder\n first: $pageLimit\n after: $cursor\n point: $point\n ) {\n __typename\n edges {\n __typename\n node {\n __typename\n id\n videoId\n videoPlaybackDashUrl\n videoPlaybackHlsUrl\n videoDownloadMp4Url\n videoThumbnailUrl\n videoState\n text\n userEmoji\n userColor\n secondaryUserColor\n distance\n geohash\n interestAreas\n createdAt\n commentCount\n voteCount\n isIncognito\n isMine\n isReported\n myVote\n threadId\n isReplyable\n notificationsEnabled\n }\n }\n pageInfo {\n __typename\n endCursor\n hasNextPage\n }\n }\n}',
'variables': {
'cursor': None,
'feedOrder': "HOT",
'feedType': 'LOCAL',
'pageLimit': None,
'point': f'POINT({Point[1]} {Point[0]})',
},
}
response = requests.post('https://api.yikyak.com/graphql/', headers=headers, json=json_data)
self.data = [d["node"] for d in json.loads(response.text)["data"]["feed"]["edges"]]
30 changes: 30 additions & 0 deletions api_connectors/PositionStackAPI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import requests, json, YakConnection

class PositionStackAPI(YakConnection.Connection): # POSITION STACK AP
def __init__(self):
super().__init__()
self.api_key = self.get_setting("POSITION_STACK_API_KEY")

def ReverseGeocode(self,Point): #Get Landmark Name From Coordinate
params = {
'access_key': self.api_key,
'query': f'{Point[0]},{Point[1]}',
}
data = requests.get('http://api.positionstack.com/v1/reverse', params=params)
data = json.loads(data.text)["data"]
for p in data:
if p['type'] == "address":
return p['name']

return data["data"][0]['name']

def ForwardGeocode(self, Address): # Get Landmark Name From Address
params = {
'access_key': self.api_key,
'query': Address,
'reigon':'North America',
'limit':1
}
data = requests.get('http://api.positionstack.com/v1/forward', params=params)
data = json.loads(data.text)["data"][0]
return (data["latitude"], data["longitude"])
27 changes: 27 additions & 0 deletions api_connectors/YakConnection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import requests, json, PositionStackAPI

class Connection:
def __init__(self, config_path):
self.connection_settings = json.load(open(config_path))

def get_setting(self, key):
return self.connection_settings[key]


class AccessToken(Connection): #Access / Id Token TODO: Implement better solution to retreiving access token
def __init__(self):
super().__init__()
headers = self.get_setting('headers')

params = {
'key': self.get_setting("key"),
}

json_data = {
'grantType': 'refresh_token',
'refreshToken': self.get_setting('refresh_token'),
}

self.response = requests.post('https://securetoken.googleapis.com/v1/token', params=params, headers=headers, json=json_data)
def __str__(self) -> str:
return json.loads(self.response.text)['access_token']
17 changes: 17 additions & 0 deletions connection.json.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"refresh_token":"[REFRESH TOKEN]",

"headers":{
"x-client-version": "iOS/FirebaseSDK/9.0.0/FirebaseCore-iOS",
"content-type": "application/json",
"accept": "*/*",
"x-ios-bundle-identifier": "com.yikyak.2",
"user-agent": "FirebaseAuth.iOS/9.0.0 com.yikyak.2/3.0.3 iPhone/16.1.1 hw/iPhone14_6",
"accept-language": "en"
},

"key":"[YIKYAK_KEY]",

"POSITION_STACK_API_KEY":"[POSITION STACK API KEY]"
}
remove this line and save as connection.json
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.