Skip to content

Commit cfef0bb

Browse files
committed
tools in progress, currently facing some dvc woes
1 parent 74bb39b commit cfef0bb

14 files changed

+25016
-1173
lines changed

.dvcignore

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
# Add patterns of files dvc should ignore, which could improve
22
# the performance. Learn more at
33
# https://dvc.org/doc/user-guide/dvcignore
4+
# .dvcignore is similar to .gitignore in Git, and can be tested
5+
# with our helper command 'dvc check-ignore'.
6+
7+
# ignoring Mac-specific files
8+
.DS_Store
9+
10+
# ignoring youtube downloads for now...
11+
data/audio_downloads/*
12+
13+
# tbd...

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
__pycache__/
33
*.py[cod]
44
*$py.class
5+
.DS_Store
6+
.Rhistory
57

68
# C extensions
79
*.so
@@ -131,3 +133,4 @@ dmypy.json
131133
# DVC data repos
132134
.dvc/
133135
/data
136+
!data/*.dvc

Apple Music Helper.ipynb

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@
2020
"source": [
2121
"import applemusicpy\n",
2222
"\n",
23-
"secret_key = 'x'\n",
24-
"key_id = 'y'\n",
25-
"team_id = 'z'\n",
26-
"'''\n",
23+
"secret_key = \"x\"\n",
24+
"key_id = \"y\"\n",
25+
"team_id = \"z\"\n",
26+
"\"\"\"\n",
2727
"am = applemusicpy.AppleMusic(secret_key, key_id, team_id)\n",
2828
"results = am.search('travis scott', types=['albums'], limit=5)\n",
2929
"\n",
3030
"for item in results['results']['albums']['data']:\n",
3131
" print(item['attributes']['name'])\n",
32-
"'''"
32+
"\"\"\""
3333
]
3434
},
3535
{

Big 5 Text Analysis; Data encoding.ipynb

+9-6
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@
156156
" \"duration_ms\",\n",
157157
" \"loudness\",\n",
158158
"]\n",
159-
"audio_df = song_df.drop(columns=[col for col in list(song_df.columns) if col not in audio_cols])\n",
159+
"audio_df = song_df.drop(\n",
160+
" columns=[col for col in list(song_df.columns) if col not in audio_cols]\n",
161+
")\n",
160162
"\n",
161163
"# view df...\n",
162164
"song_df.info()"
@@ -183,7 +185,7 @@
183185
"# Combined plot.\n",
184186
"fig, (ax0, ax1, ax2, ax3) = plt.subplots(ncols=4, figsize=(20, 8))\n",
185187
"\n",
186-
"ax0.set_title('Original Distributions')\n",
188+
"ax0.set_title(\"Original Distributions\")\n",
187189
"for col in audio_cols:\n",
188190
" sns.kdeplot(audio_df[col], ax=ax0)\n",
189191
"\n",
@@ -193,7 +195,7 @@
193195
"df_mm = pd.DataFrame(df_mm, columns=list(audio_df.columns))\n",
194196
"\n",
195197
"# Viewing results...\n",
196-
"ax1.set_title('After MinMaxScaler')\n",
198+
"ax1.set_title(\"After MinMaxScaler\")\n",
197199
"for col in audio_cols:\n",
198200
" sns.kdeplot(df_mm[col], ax=ax1)\n",
199201
"\n",
@@ -203,7 +205,7 @@
203205
"df_r = pd.DataFrame(df_r, columns=list(audio_df.columns))\n",
204206
"\n",
205207
"# Viewing results...\n",
206-
"ax2.set_title('After RobustScaler')\n",
208+
"ax2.set_title(\"After RobustScaler\")\n",
207209
"for col in audio_cols:\n",
208210
" sns.kdeplot(df_r[col], ax=ax2)\n",
209211
"\n",
@@ -213,7 +215,7 @@
213215
"df_s = pd.DataFrame(df_s, columns=list(audio_df.columns))\n",
214216
"\n",
215217
"# Viewing results...\n",
216-
"ax3.set_title('After StandardScaler')\n",
218+
"ax3.set_title(\"After StandardScaler\")\n",
217219
"for col in audio_cols:\n",
218220
" sns.kdeplot(df_s[col], ax=ax3)"
219221
]
@@ -226,6 +228,7 @@
226228
"outputs": [],
227229
"source": [
228230
"from pandas_profiling import ProfileReport\n",
231+
"\n",
229232
"prof = ProfileReport(song_df)"
230233
]
231234
},
@@ -93733,7 +93736,7 @@
9373393736
"# Scaling, standardizing & normalizing\n",
9373493737
"\n",
9373593738
"mm_scaler = preprocessing.MinMaxScaler()\n",
93736-
"#X_train_minmax = mm_scaler.fit_transform(X_train)\n",
93739+
"# X_train_minmax = mm_scaler.fit_transform(X_train)\n",
9373793740
"\n",
9373893741
"song_df[\"norm_duration_ms\"] = song_df.duration_ms / song_df.duration_ms.max()\n",
9373993742
"song_df[\"norm_loudness\"] = song_df.loudness.abs() / song_df.loudness.abs().max()\n",

Facebook Tool.ipynb

+111-69
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
{
1313
"cell_type": "code",
14-
"execution_count": 9,
14+
"execution_count": 3,
1515
"id": "fb4133a5",
1616
"metadata": {},
1717
"outputs": [
@@ -21,13 +21,14 @@
2121
"True"
2222
]
2323
},
24-
"execution_count": 9,
24+
"execution_count": 3,
2525
"metadata": {},
2626
"output_type": "execute_result"
2727
}
2828
],
2929
"source": [
30-
"import facebook\n",
30+
"import facebook # unclear if this library still works...\n",
31+
"\n",
3132
"import os\n",
3233
"import sys\n",
3334
"import json\n",
@@ -44,35 +45,117 @@
4445
},
4546
{
4647
"cell_type": "code",
47-
"execution_count": 21,
48+
"execution_count": 25,
49+
"id": "3526b051",
50+
"metadata": {},
51+
"outputs": [
52+
{
53+
"name": "stdout",
54+
"output_type": "stream",
55+
"text": [
56+
"\n",
57+
"failure\n"
58+
]
59+
}
60+
],
61+
"source": [
62+
"def test_func(**kwargs):\n",
63+
" print(kwargs.get(\"first_name\", \"\"))\n",
64+
" print(kwargs.get(\"first_name\", \"failure\"))\n",
65+
"\n",
66+
"\n",
67+
"# test_str = kwargs.get('first_name','') + kwargs.get('first_nam','') + kwargs.get('last_name','')\n",
68+
"# print(test_str)\n",
69+
"# if kwargs:\n",
70+
"# print('yes')\n",
71+
"# else:\n",
72+
"# print('no')\n",
73+
"test_func()"
74+
]
75+
},
76+
{
77+
"cell_type": "code",
78+
"execution_count": 38,
4879
"id": "34d6a9fa",
4980
"metadata": {},
5081
"outputs": [],
5182
"source": [
5283
"class facebookHelper:\n",
5384
" def __init__(self):\n",
85+
" # music_mapping credentials\n",
5486
" self.appID = os.environ.get(\"facebookAppID\")\n",
5587
" self.access_token = os.environ.get(\"facebookAppAcessToken\")\n",
5688
" self.user_token = os.environ.get(\"facebookUserAccessToken\")\n",
89+
" # yoU credentials\n",
90+
" self.old_token = os.environ.get(\"oldFbID\")\n",
91+
" self.old_secret = os.environ.get(\"oldSecret\")\n",
92+
" # default fields\n",
93+
" self.base_url = \"https://graph.facebook.com/v\"\n",
5794
" self.data_path = \"/Users/dayoorigunwa/code_base/music_mapping/data/\"\n",
58-
" #self.sp = self.getClient()\n",
59-
" \n",
95+
" # self.sp = self.getClient()\n",
96+
"\n",
6097
" def __str__(self):\n",
6198
" return \"Facebook API Helper\"\n",
62-
" \n",
63-
" def get_graph(self):\n",
64-
" return facebook.GraphAPI(access_token=self.user_token, version='3.1')"
99+
"\n",
100+
" def _request_args(self):\n",
101+
" args = {\n",
102+
" \"version\": \"12.0\",\n",
103+
" \"node\": \"me\",\n",
104+
" \"field_sep\": \"%2C\",\n",
105+
" \"creds_sep\": \"&\",\n",
106+
" \"fields\": [\"id\", \"name\", \"email\"],\n",
107+
" }\n",
108+
" return args\n",
109+
"\n",
110+
" def build_request(self, **kwargs):\n",
111+
" # NOTE: Access token required for this to resolve...\n",
112+
" mArgs = self._request_args() if not kwargs else kwargs\n",
113+
" query_1 = \"https://graph.facebook.com/v12.0/me?fields=id%2Cname%2Cemail&transport=cors&access_token=EAAGOLqHzArABAPBtrJMN7pUyWjrYRrvDzDqy7st3qy3JhcBAYmn8ZAzehiMv4wyEKI9853wdTs4E3Il4C1rARdIcQMyfEegyVSbEez3cnfZAgEwQyovlFPuexsRnOZB3cWeUsxEYM6Bab3i5Bz9RPZAAw1zJUM2ZBZAZAUWhIgMKsPliutt7t4w9zsV45f0YQ2FtPBM2xsjOAZDZD\"\n",
114+
" query = self.base_url + mArgs.get(\"version\", \"\") + \"/\" + mArgs.get(\"node\", \"\")\n",
115+
" if mArgs.get(\"fields\", \"\"):\n",
116+
" query += \"?fields=\"\n",
117+
" for fld in mArgs.get(\"fields\"):\n",
118+
" query += fld + mArgs.get(\"field_sep\")\n",
119+
" return query\n",
120+
"\n",
121+
" def get_graph(self, creds=\"legacy\"):\n",
122+
" if creds == \"legacy\":\n",
123+
" return facebook.GraphAPI(access_token=self.user_token, version=\"3.1\")\n",
124+
" else:\n",
125+
" return facebook.GraphAPI(access_token=self.user_token, version=\"3.1\")"
65126
]
66127
},
67128
{
68129
"cell_type": "code",
69-
"execution_count": 22,
130+
"execution_count": 39,
131+
"id": "e689d538",
132+
"metadata": {},
133+
"outputs": [
134+
{
135+
"data": {
136+
"text/plain": [
137+
"'https://graph.facebook.com/v12.0/me?fields=id%2Cname%2Cemail%2C'"
138+
]
139+
},
140+
"execution_count": 39,
141+
"metadata": {},
142+
"output_type": "execute_result"
143+
}
144+
],
145+
"source": [
146+
"fb = facebookHelper()\n",
147+
"fb.build_request()"
148+
]
149+
},
150+
{
151+
"cell_type": "code",
152+
"execution_count": 5,
70153
"id": "ed34b513",
71154
"metadata": {},
72155
"outputs": [],
73156
"source": [
74157
"fb = facebookHelper()\n",
75-
"g = fb.get_graph()"
158+
"g = fb.get_graph(creds=\"legacy\")"
76159
]
77160
},
78161
{
@@ -155,7 +238,7 @@
155238
},
156239
{
157240
"cell_type": "code",
158-
"execution_count": 36,
241+
"execution_count": 6,
159242
"id": "762f4f04",
160243
"metadata": {},
161244
"outputs": [
@@ -166,19 +249,19 @@
166249
"traceback": [
167250
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
168251
"\u001b[0;31mGraphAPIError\u001b[0m Traceback (most recent call last)",
169-
"\u001b[0;32m/var/folders/9f/0jslw5zs3rg1hqt9w92zlbv00000gn/T/ipykernel_14646/962639775.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mg\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrequest\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'/search?q=test&type=event&limit=10000'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
252+
"\u001b[0;32m/var/folders/9f/0jslw5zs3rg1hqt9w92zlbv00000gn/T/ipykernel_28371/962639775.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mg\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrequest\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'/search?q=test&type=event&limit=10000'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
170253
"\u001b[0;32m~/.pyenv/versions/3.7.4/envs/music/lib/python3.7/site-packages/facebook/__init__.py\u001b[0m in \u001b[0;36mrequest\u001b[0;34m(self, path, args, post_args, files, method)\u001b[0m\n\u001b[1;32m 311\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 312\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mresult\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdict\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"error\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 313\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mGraphAPIError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 314\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 315\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
171254
"\u001b[0;31mGraphAPIError\u001b[0m: (#3) Application does not have the capability to make this API call."
172255
]
173256
}
174257
],
175258
"source": [
176-
"g.request(path='/search?q=test&type=event&limit=10000')"
259+
"g.request(path=\"/search?q=test&type=event&limit=10000\")"
177260
]
178261
},
179262
{
180263
"cell_type": "code",
181-
"execution_count": 32,
264+
"execution_count": 7,
182265
"id": "9027cb00",
183266
"metadata": {},
184267
"outputs": [
@@ -188,7 +271,7 @@
188271
"'v3.1'"
189272
]
190273
},
191-
"execution_count": 32,
274+
"execution_count": 7,
192275
"metadata": {},
193276
"output_type": "execute_result"
194277
}
@@ -199,72 +282,31 @@
199282
},
200283
{
201284
"cell_type": "code",
202-
"execution_count": 24,
285+
"execution_count": 8,
203286
"id": "e66b5a40",
204287
"metadata": {},
205288
"outputs": [
206289
{
207290
"data": {
208291
"text/plain": [
209-
"['__class__',\n",
210-
" '__delattr__',\n",
211-
" '__dict__',\n",
212-
" '__dir__',\n",
213-
" '__doc__',\n",
214-
" '__eq__',\n",
215-
" '__format__',\n",
216-
" '__ge__',\n",
217-
" '__getattribute__',\n",
218-
" '__gt__',\n",
219-
" '__hash__',\n",
220-
" '__init__',\n",
221-
" '__init_subclass__',\n",
222-
" '__le__',\n",
223-
" '__lt__',\n",
224-
" '__module__',\n",
225-
" '__ne__',\n",
226-
" '__new__',\n",
227-
" '__reduce__',\n",
228-
" '__reduce_ex__',\n",
229-
" '__repr__',\n",
230-
" '__setattr__',\n",
231-
" '__sizeof__',\n",
232-
" '__str__',\n",
233-
" '__subclasshook__',\n",
234-
" '__weakref__',\n",
235-
" 'access_token',\n",
236-
" 'debug_access_token',\n",
237-
" 'delete_object',\n",
238-
" 'delete_request',\n",
239-
" 'extend_access_token',\n",
240-
" 'get_access_token_from_code',\n",
241-
" 'get_all_connections',\n",
242-
" 'get_app_access_token',\n",
243-
" 'get_auth_url',\n",
244-
" 'get_connections',\n",
245-
" 'get_object',\n",
246-
" 'get_objects',\n",
247-
" 'get_permissions',\n",
248-
" 'get_version',\n",
249-
" 'proxies',\n",
250-
" 'put_comment',\n",
251-
" 'put_like',\n",
252-
" 'put_object',\n",
253-
" 'put_photo',\n",
254-
" 'request',\n",
255-
" 'search',\n",
256-
" 'session',\n",
257-
" 'timeout',\n",
258-
" 'version']"
292+
"{'id': '10208907223354367',\n",
293+
" 'name': 'Dayo Origunwa',\n",
294+
" 'email': '[email protected]'}"
259295
]
260296
},
261-
"execution_count": 24,
297+
"execution_count": 8,
262298
"metadata": {},
263299
"output_type": "execute_result"
264300
}
265301
],
266302
"source": [
267-
"list(dir(g))"
303+
"# testing a curl replication\n",
304+
"test_link = \"https://graph.facebook.com/v12.0/me?fields=id%2Cname%2Cemail&transport=cors&access_token=EAAGOLqHzArABAPBtrJMN7pUyWjrYRrvDzDqy7st3qy3JhcBAYmn8ZAzehiMv4wyEKI9853wdTs4E3Il4C1rARdIcQMyfEegyVSbEez3cnfZAgEwQyovlFPuexsRnOZB3cWeUsxEYM6Bab3i5Bz9RPZAAw1zJUM2ZBZAZAUWhIgMKsPliutt7t4w9zsV45f0YQ2FtPBM2xsjOAZDZD\"\n",
305+
"\n",
306+
"import requests\n",
307+
"\n",
308+
"r = requests.get(test_link)\n",
309+
"r.json()"
268310
]
269311
},
270312
{

0 commit comments

Comments
 (0)