scraper.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:DublinBikeApp 作者: charlawl 项目源码 文件源码
def insert_db_weather(weather_values):
    """Function for inserting scraped data from Weather API into database"""
    session = Session()
    new_data = Weather(coord_lon=weather_values["coord"]["lon"],
                       coord_lat=weather_values["coord"]["lat"],
                       weather_id=weather_values["weather"][0]["id"],
                       weather_main=weather_values["weather"][0]["main"],
                       weather_description=weather_values["weather"][0]["description"],
                       weather_icon=weather_values["weather"][0]["icon"],
                       base=weather_values["base"],
                       main_temp=weather_values["main"]["temp"],
                       main_pressure=weather_values["main"]["pressure"],
                       main_humidity=weather_values["main"]["humidity"],
                       main_temp_min=weather_values["main"]["temp_min"],
                       main_temp_max=weather_values["main"]["temp_max"],
                       visibility=weather_values["visibility"],
                       wind_speed=weather_values["wind"]["speed"],
                       wind_deg=weather_values["wind"]["deg"],
                       clouds_all=weather_values["clouds"]["all"],
                       dt=datetime.fromtimestamp(weather_values["dt"]),
                       sys_type=weather_values["sys"]["type"],
                       sys_id=weather_values["sys"]["id"],
                       sys_message=weather_values["sys"]["message"],
                       sys_country=weather_values["sys"]["country"],
                       sys_sunrise=datetime.fromtimestamp(weather_values["sys"]["sunrise"]),
                       sys_sunset=datetime.fromtimestamp(weather_values["sys"]["sunset"]),
                       city_id=weather_values["id"],
                       city_name=weather_values["name"],
                       cod=weather_values["cod"])
    session.add(new_data)
    session.commit()
    session.close()

# Running the scraper
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号