Comments (4)
Solution on linux is to add a -
in the %d and %I to remove padded zeros from what it expects:
dt_object = dt.datetime.strptime('2023 9 Apr 2:52 PM EDT', '%Y %-d %b %-I:%M %p %Z')
Im not sure how to accomplish this on windows
from retrofeed.
Solution on Windows was to just remove that section. Here is the updated weather.py script:
from bs4 import BeautifulSoup
import datetime as dt
import requests
import string_processing as sp
# Populate an existing weather object with approprate values
# when weather data is not available
def assign_errors(wx):
wx['conditions_location'] = 'N/A'
wx['currently'] = 'N/A'
wx['temp_f'] = 'N/A'
wx['temp_c'] = ''
wx['comfort'] = ''
wx['last_update'] = 'N/A'
wx['wind_speed'] = 'N/A'
wx['visibility'] = 'N/A'
wx['dewpoint'] = 'N/A'
wx['periods'] = [{'timeframe':'Forecast Not Available',
'forecast':''}]
return wx
def get_comfort_from_dewpoint(dp_text):
dp = int(dp_text.split('F')[0])
if dp < 50:
return 'Dry'
if dp <= 60:
return 'Pleasant'
if dp <= 65:
return 'Slightly Humid'
if dp <= 70:
return 'Humid'
if dp <= 75:
return 'Very Humid'
return 'Oppressive'
# Gets weather for a specific lat/lon in the US from weather.gov
# Returns a dictionary with various weather elements
def get_weather(lat, lon, location=None):
wx = {'fetched_on':dt.datetime.now(),
'location':location,
'periods':[],
'hazards':[] }
#url = f'https://forecast.weather.gov/MapClick.php?textField1={lat}&textField2={lon}'
url = f'https://forecast.weather.gov/MapClick.php?lat={lat}&lon={lon}'
#print(url)
response = requests.get(url, headers={'Cache-Control':'no-cache', 'Pragma':'no-cache'})
if response.status_code != 200:
return(assign_errors(wx))
#print(response.headers)
soup = BeautifulSoup(response.text, 'html.parser')
# Test check one element to make sure the site's showing weather
if (soup.find('h2', 'panel-title')) is None:
return(assign_errors(wx))
wx['conditions_location'] = sp.clean_chars(soup.find('h2', 'panel-title').string)
if wx['location'] == None:
wx['location'] = ['conditions_location']
wx['currently'] = sp.clean_chars(soup.find('p', 'myforecast-current').string)
wx['temp_f'] = sp.clean_chars(soup.find('p', 'myforecast-current-lrg').string)
wx['temp_c'] = sp.clean_chars(soup.find('p', 'myforecast-current-sm').string)
# Various weather stats are stored as table data in the sole table
cells = soup.find_all('td')
key = None
for cell in cells:
if key is None:
key = cell.string.lower().replace(' ', '_')
else:
wx[key] = sp.clean_chars(cell.string)
key = None
# Try to convert the "last_update" text to a real datetime value
# Text description of the dewpoint
wx['comfort'] = get_comfort_from_dewpoint(wx['dewpoint'])
# Get period forecast from the alt-text of the weather icons
icons = soup.find_all('img', 'forecast-icon')
for icon in icons:
alt_text = icon['alt']
if alt_text is None or alt_text.strip() == '':
continue
split_text = alt_text.split(':', 1)
if len(split_text) == 2:
period = {'timeframe':sp.clean_chars(split_text[0]),
'forecast':sp.clean_chars(split_text[1])}
wx['periods'].append(period)
# Any hazard headlines?
hazards = soup.find_all('a', 'anchor-hazards')
for hazard in hazards:
stripped_haz = hazard.contents[0].strip()
if stripped_haz != 'Hazardous Weather Outlook' and stripped_haz != '':
wx['hazards'].append(sp.clean_chars(stripped_haz))
return wx
from retrofeed.
I had a similar issue in spot-the-station.py and fixed with:
changed ./segments/spot-the-station.py;
#LINE 70 changed to:
Assuming the input is always "{ts '...'}"
date_string_clean = date_string[5:-2]
date_time = dt.datetime.strptime(date_string_clean, '%Y-%m-%d %H:%M:%S') - utc_diff
I'm now trying to find an issue w/ ap_news.py and its formatting must have changed and I can only get "NEWSFEED UNAVAILABLE"...
from retrofeed.
New version should've fixed this, although I haven't tested it on every platform.
from retrofeed.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from retrofeed.