39 files changed +971
-654
lines changed Original file line number Diff line number Diff line change 8
8
Rating). We try to best fit a line through dataset and estimate the parameters.
9
9
"""
10
10
11
+ # /// script
12
+ # requires-python = ">=3.13"
13
+ # dependencies = [
14
+ # "httpx",
15
+ # "numpy",
16
+ # ]
17
+ # ///
18
+
19
+ import httpx
11
20
import numpy as np
12
- import requests
13
21
14
22
15
23
def collect_dataset ():
16
24
"""Collect dataset of CSGO
17
25
The dataset contains ADR vs Rating of a Player
18
26
:return : dataset obtained from the link, as matrix
19
27
"""
20
- response = requests .get (
28
+ response = httpx .get (
21
29
"https://raw.githubusercontent.com/yashLadha/The_Math_of_Intelligence/"
22
30
"master/Week1/ADRvsRating.csv" ,
23
31
timeout = 10 ,
Original file line number Diff line number Diff line change @@ -59,9 +59,9 @@ def avg_speed_of_molecule(temperature: float, molar_mass: float) -> float:
59
59
Examples:
60
60
61
61
>>> avg_speed_of_molecule(273, 0.028) # nitrogen at 273 K
62
- 454.3488755020387
62
+ 454.3488755062257
63
63
>>> avg_speed_of_molecule(300, 0.032) # oxygen at 300 K
64
- 445.52572733919885
64
+ 445.5257273433045
65
65
>>> avg_speed_of_molecule(-273, 0.028) # invalid temperature
66
66
Traceback (most recent call last):
67
67
...
@@ -87,9 +87,9 @@ def mps_speed_of_molecule(temperature: float, molar_mass: float) -> float:
87
87
Examples:
88
88
89
89
>>> mps_speed_of_molecule(273, 0.028) # nitrogen at 273 K
90
- 402.65620701908966
90
+ 402.65620702280023
91
91
>>> mps_speed_of_molecule(300, 0.032) # oxygen at 300 K
92
- 394.836895549922
92
+ 394.8368955535605
93
93
>>> mps_speed_of_molecule(-273, 0.028) # invalid temperature
94
94
Traceback (most recent call last):
95
95
...
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ classifiers = [
11
11
dependencies = [
12
12
" beautifulsoup4>=4.12.3" ,
13
13
" fake-useragent>=1.5.1" ,
14
+ " httpx>=0.28.1" ,
14
15
" imageio>=2.36.1" ,
15
16
" keras>=3.7" ,
16
17
" lxml>=5.3" ,
@@ -19,7 +20,6 @@ dependencies = [
19
20
" opencv-python>=4.10.0.84" ,
20
21
" pandas>=2.2.3" ,
21
22
" pillow>=11" ,
22
- " requests>=2.32.3" ,
23
23
" rich>=13.9.4" ,
24
24
" scikit-learn>=1.5.2" ,
25
25
" sphinx-pyproject>=0.3" ,
@@ -42,8 +42,8 @@ docs = [
42
42
" sphinx-pyproject>=0.3" ,
43
43
]
44
44
euler-validate = [
45
+ " httpx>=0.28.1" ,
45
46
" numpy>=2.1.3" ,
46
- " requests>=2.32.3" ,
47
47
]
48
48
49
49
[tool .ruff ]
Original file line number Diff line number Diff line change 1
1
beautifulsoup4
2
2
fake-useragent
3
+ httpx
3
4
imageio
4
5
keras
5
6
lxml
8
9
opencv-python
9
10
pandas
10
11
pillow
11
- requests
12
12
rich
13
13
scikit-learn
14
14
sphinx-pyproject
Original file line number Diff line number Diff line change 3
3
# /// script
4
4
# requires-python = ">=3.13"
5
5
# dependencies = [
6
+ # "httpx",
6
7
# "pytest",
7
- # "requests",
8
8
# ]
9
9
# ///
10
10
15
15
import pathlib
16
16
from types import ModuleType
17
17
18
+ import httpx
18
19
import pytest
19
- import requests
20
20
21
21
PROJECT_EULER_DIR_PATH = pathlib .Path .cwd ().joinpath ("project_euler" )
22
22
PROJECT_EULER_ANSWERS_PATH = pathlib .Path .cwd ().joinpath (
@@ -66,7 +66,7 @@ def added_solution_file_path() -> list[pathlib.Path]:
66
66
"Accept" : "application/vnd.github.v3+json" ,
67
67
"Authorization" : "token " + os .environ ["GITHUB_TOKEN" ],
68
68
}
69
- files = requests .get (get_files_url (), headers = headers , timeout = 10 ).json ()
69
+ files = httpx .get (get_files_url (), headers = headers , timeout = 10 ).json ()
70
70
for file in files :
71
71
filepath = pathlib .Path .cwd ().joinpath (file ["filename" ])
72
72
if (
Original file line number Diff line number Diff line change 2
2
Get CO2 emission data from the UK CarbonIntensity API
3
3
"""
4
4
5
+ # /// script
6
+ # requires-python = ">=3.13"
7
+ # dependencies = [
8
+ # "httpx",
9
+ # ]
10
+ # ///
11
+
5
12
from datetime import date
6
13
7
- import requests
14
+ import httpx
8
15
9
16
BASE_URL = "https://api.carbonintensity.org.uk/intensity"
10
17
11
18
12
19
# Emission in the last half hour
13
20
def fetch_last_half_hour () -> str :
14
- last_half_hour = requests .get (BASE_URL , timeout = 10 ).json ()["data" ][0 ]
21
+ last_half_hour = httpx .get (BASE_URL , timeout = 10 ).json ()["data" ][0 ]
15
22
return last_half_hour ["intensity" ]["actual" ]
16
23
17
24
18
25
# Emissions in a specific date range
19
26
def fetch_from_to (start , end ) -> list :
20
- return requests .get (f"{ BASE_URL } /{ start } /{ end } " , timeout = 10 ).json ()["data" ]
27
+ return httpx .get (f"{ BASE_URL } /{ start } /{ end } " , timeout = 10 ).json ()["data" ]
21
28
22
29
23
30
if __name__ == "__main__" :
Original file line number Diff line number Diff line change 4
4
more convenient to use in Python web projects (e.g. Django or Flask-based)
5
5
"""
6
6
7
+ # /// script
8
+ # requires-python = ">=3.13"
9
+ # dependencies = [
10
+ # "httpx",
11
+ # "lxml",
12
+ # ]
13
+ # ///
14
+
7
15
from typing import NamedTuple
8
16
9
- import requests
17
+ import httpx
10
18
from lxml import html
11
19
12
20
@@ -19,7 +27,7 @@ class CovidData(NamedTuple):
19
27
def covid_stats (url : str = "https://www.worldometers.info/coronavirus/" ) -> CovidData :
20
28
xpath_str = '//div[@class = "maincounter-number"]/span/text()'
21
29
return CovidData (
22
- * html .fromstring (requests .get (url , timeout = 10 ).content ).xpath (xpath_str )
30
+ * html .fromstring (httpx .get (url , timeout = 10 ).content ).xpath (xpath_str )
23
31
)
24
32
25
33
Original file line number Diff line number Diff line change
1
+ # /// script
2
+ # requires-python = ">=3.13"
3
+ # dependencies = [
4
+ # "beautifulsoup4",
5
+ # "fake-useragent",
6
+ # "httpx",
7
+ # ]
8
+ # ///
9
+
1
10
import sys
2
11
import webbrowser
3
12
4
- import requests
13
+ import httpx
5
14
from bs4 import BeautifulSoup
6
15
from fake_useragent import UserAgent
7
16
8
17
if __name__ == "__main__" :
9
18
print ("Googling....." )
10
19
url = "https://www.google.com/search?q=" + " " .join (sys .argv [1 :])
11
- res = requests .get (url , headers = {"UserAgent" : UserAgent ().random }, timeout = 10 )
20
+ res = httpx .get (
21
+ url ,
22
+ headers = {"UserAgent" : UserAgent ().random },
23
+ timeout = 10 ,
24
+ follow_redirects = True ,
25
+ )
12
26
# res.raise_for_status()
13
27
with open ("project1a.html" , "wb" ) as out_file : # only for knowing the class
14
28
for data in res .iter_content (10000 ):
Original file line number Diff line number Diff line change 3
3
using title and year of publication, and volume and pages of journal.
4
4
"""
5
5
6
- import requests
6
+ # /// script
7
+ # requires-python = ">=3.13"
8
+ # dependencies = [
9
+ # "beautifulsoup4",
10
+ # "httpx",
11
+ # ]
12
+ # ///
13
+
14
+ import httpx
7
15
from bs4 import BeautifulSoup
8
16
9
17
@@ -12,7 +20,7 @@ def get_citation(base_url: str, params: dict) -> str:
12
20
Return the citation number.
13
21
"""
14
22
soup = BeautifulSoup (
15
- requests .get (base_url , params = params , timeout = 10 ).content , "html.parser"
23
+ httpx .get (base_url , params = params , timeout = 10 ).content , "html.parser"
16
24
)
17
25
div = soup .find ("div" , attrs = {"class" : "gs_ri" })
18
26
anchors = div .find ("div" , attrs = {"class" : "gs_fl" }).find_all ("a" )
Original file line number Diff line number Diff line change 3
3
https://www.amdoren.com
4
4
"""
5
5
6
+ # /// script
7
+ # requires-python = ">=3.13"
8
+ # dependencies = [
9
+ # "httpx",
10
+ # ]
11
+ # ///
12
+
6
13
import os
7
14
8
- import requests
15
+ import httpx
9
16
10
17
URL_BASE = "https://www.amdoren.com/api/currency.php"
11
18
@@ -176,7 +183,7 @@ def convert_currency(
176
183
params = locals ()
177
184
# from is a reserved keyword
178
185
params ["from" ] = params .pop ("from_" )
179
- res = requests .get (URL_BASE , params = params , timeout = 10 ).json ()
186
+ res = httpx .get (URL_BASE , params = params , timeout = 10 ).json ()
180
187
return str (res ["amount" ]) if res ["error" ] == 0 else res ["error_message" ]
181
188
182
189
Original file line number Diff line number Diff line change 1
- import requests
1
+ # /// script
2
+ # requires-python = ">=3.13"
3
+ # dependencies = [
4
+ # "beautifulsoup4",
5
+ # "httpx",
6
+ # ]
7
+ # ///
8
+
9
+ import httpx
2
10
from bs4 import BeautifulSoup
3
11
4
12
"""
@@ -20,8 +28,8 @@ def stock_price(symbol: str = "AAPL") -> str:
20
28
True
21
29
"""
22
30
url = f"https://finance.yahoo.com/quote/{ symbol } ?p={ symbol } "
23
- yahoo_finance_source = requests .get (
24
- url , headers = {"USER-AGENT" : "Mozilla/5.0" }, timeout = 10
31
+ yahoo_finance_source = httpx .get (
32
+ url , headers = {"USER-AGENT" : "Mozilla/5.0" }, timeout = 10 , follow_redirects = True
25
33
).text
26
34
soup = BeautifulSoup (yahoo_finance_source , "html.parser" )
27
35
Original file line number Diff line number Diff line change 1
- import requests
1
+ # /// script
2
+ # requires-python = ">=3.13"
3
+ # dependencies = [
4
+ # "httpx",
5
+ # ]
6
+ # ///
7
+
8
+ import httpx
2
9
3
10
# Put your API key(s) here
4
11
OPENWEATHERMAP_API_KEY = ""
@@ -19,13 +26,13 @@ def current_weather(location: str) -> list[dict]:
19
26
weather_data = []
20
27
if OPENWEATHERMAP_API_KEY :
21
28
params_openweathermap = {"q" : location , "appid" : OPENWEATHERMAP_API_KEY }
22
- response_openweathermap = requests .get (
29
+ response_openweathermap = httpx .get (
23
30
OPENWEATHERMAP_URL_BASE , params = params_openweathermap , timeout = 10
24
31
)
25
32
weather_data .append ({"OpenWeatherMap" : response_openweathermap .json ()})
26
33
if WEATHERSTACK_API_KEY :
27
34
params_weatherstack = {"query" : location , "access_key" : WEATHERSTACK_API_KEY }
28
- response_weatherstack = requests .get (
35
+ response_weatherstack = httpx .get (
29
36
WEATHERSTACK_URL_BASE , params = params_weatherstack , timeout = 10
30
37
)
31
38
weather_data .append ({"Weatherstack" : response_weatherstack .json ()})
Original file line number Diff line number Diff line change 1
- import requests
1
+ # /// script
2
+ # requires-python = ">=3.13"
3
+ # dependencies = [
4
+ # "beautifulsoup4",
5
+ # "httpx",
6
+ # ]
7
+ # ///
8
+
9
+ import httpx
2
10
from bs4 import BeautifulSoup
3
11
4
12
@@ -7,7 +15,7 @@ def horoscope(zodiac_sign: int, day: str) -> str:
7
15
"https://www.horoscope.com/us/horoscopes/general/"
8
16
f"horoscope-general-daily-{ day } .aspx?sign={ zodiac_sign } "
9
17
)
10
- soup = BeautifulSoup (requests .get (url , timeout = 10 ).content , "html.parser" )
18
+ soup = BeautifulSoup (httpx .get (url , timeout = 10 ).content , "html.parser" )
11
19
return soup .find ("div" , class_ = "main-horoscope" ).p .text
12
20
13
21
Original file line number Diff line number Diff line change
1
+ # /// script
2
+ # requires-python = ">=3.13"
3
+ # dependencies = [
4
+ # "beautifulsoup4",
5
+ # "httpx",
6
+ # ]
7
+ # ///
8
+
1
9
import json
2
10
import os
3
11
import re
4
12
import sys
5
13
import urllib .request
6
14
7
- import requests
15
+ import httpx
8
16
from bs4 import BeautifulSoup
9
17
10
18
headers = {
@@ -39,7 +47,7 @@ def download_images_from_google_query(query: str = "dhaka", max_images: int = 5)
39
47
"ijn" : "0" ,
40
48
}
41
49
42
- html = requests .get (
50
+ html = httpx .get (
43
51
"https://www.google.com/search" , params = params , headers = headers , timeout = 10
44
52
)
45
53
soup = BeautifulSoup (html .text , "html.parser" )
There was a problem loading the remainder of the diff.
0 commit comments