Neurolingua commited on
Commit
65a48f9
1 Parent(s): 6510d51

Update other_function.py

Browse files
Files changed (1) hide show
  1. other_function.py +27 -1
other_function.py CHANGED
@@ -157,4 +157,30 @@ def get_news():
157
  # Extract the headline
158
  headline = story.find('h3').text.strip()
159
  news.append(headline)
160
- return news
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  # Extract the headline
158
  headline = story.find('h3').text.strip()
159
  news.append(headline)
160
+ return news
161
+
162
+
163
+
164
+ def download_and_save_as_txt(url, account_sid, auth_token):
165
+ try:
166
+ # Make the request to the media URL with authentication
167
+ response = requests.get(url, auth=HTTPBasicAuth(account_sid, auth_token))
168
+ response.raise_for_status() # Raise an error for bad responses
169
+
170
+ # Determine a filename from the URL
171
+ parsed_url = urlparse(url)
172
+ media_id = parsed_url.path.split('/')[-1] # Get the last part of the URL path
173
+ filename = f"pdf_file.pdf"
174
+
175
+ # Save the media content to a .txt file
176
+ txt_filepath = os.path.join(UPLOAD_FOLDER, filename)
177
+ with open(txt_filepath, 'wb') as file:
178
+ file.write(response.content)
179
+
180
+ print(f"Media downloaded successfully and saved as {txt_filepath}")
181
+ return txt_filepath
182
+
183
+ except requests.exceptions.HTTPError as err:
184
+ print(f"HTTP error occurred: {err}")
185
+ except Exception as err:
186
+ print(f"An error occurred: {err}")