Skip to content

Commit 403a323

Browse files
author
Lennart Haack
authored
Merge pull request #11 from Lennolium/dev
v.0.1.1 Release
2 parents e4c0121 + e08d034 commit 403a323

File tree

9 files changed

+224
-70
lines changed

9 files changed

+224
-70
lines changed

.github/ISSUE_TEMPLATE/general-issue.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ body:
3030
<br>
3131
<br>
3232
33-
<a href="https://github.com/Lennolium/PrivacyShield/issues" >
33+
<a href="https://github.com/Lennolium/simple-useragent/issues" >
3434
<img src="https://img.shields.io/github/issues-raw/Lennolium/simple-useragent?style=flat-square&label=Open%20Issues&color=deepskyblue" alt="open issues" >
3535
</a>
3636

ACKNOWLEDGMENTS

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
Many thanks to the owners and maintainers of the following python packages which were used in the development of this project.
2-
Without these packages, this project would not have been possible, or at least would have been much more difficult to develop.
3-
If you are interested in learning more about these packages, please check the links below:
1+
Many thanks to the owners and maintainers of the following python
2+
packages which were used in the development of this project. Without
3+
these packages, this project would not have been possible, or at least
4+
would have been much more difficult to develop. If you are interested in
5+
learning more about these packages, please check the links below:
46

5-
- Requests: https://requests.readthedocs.io/en/master/
7+
- Requests: https://github.com/psf/requests
68
- BeautifulSoup: https://www.crummy.com/software/BeautifulSoup/bs4/doc/
7-
- platformdirs: https://platformdirs.readthedocs.io/en/latest/
9+
- platformdirs: https://github.com/platformdirs/platformdirs
810
- ua-parser: https://github.com/ua-parser/uap-python
911

10-
The base functionality of this project is built on top of the useragents.me API,
11-
which is a free service that provides user agent strings and their usage percentage
12-
for a wide variety of devices and browsers:
12+
13+
The base functionality of simple-useragent is built on top of the
14+
useragents.me API, which is a free service that provides user agent
15+
strings and their usage percentage for a wide variety of devices and
16+
browsers.
1317

1418
- UserAgents.me (Nick, stayML): https://useragents.me/

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<img src="https://app.codacy.com/project/badge/Grade/747e8fea69394b10a1f4627babddcf4f" alt="code quality" >
2020
<a></a>
2121
<a href="https://github.com/Lennolium/simple-useragent/commits/main" >
22-
<img src="https://img.shields.io/github/commit-activity/m/Lennolium/simple-useragent?label=Commit%20Activity"
22+
<img src="https://img.shields.io/github/commit-activity/m/Lennolium/simple-useragent?label=Commit%20Activity&color=yellow"
2323
alt="commit activity" >
2424
<a></a>
2525
<a href="https://github.com/Lennolium/simple-useragent/releases" >
@@ -30,8 +30,8 @@ alt="stable version" >
3030
<img src="https://img.shields.io/github/issues-raw/Lennolium/simple-useragent?label=Open%20Issues&color=critical" alt="open issues" >
3131
<a href="https://github.com/Lennolium/simple-useragent/issues?q=is%3Aissue+is%3Aclosed" >
3232
<img src="https://img.shields.io/github/issues-closed-raw/Lennolium/simple-useragent?label=Closed%20Issues&color=inactive" alt="closed issues" >
33-
<a href="#" >
34-
<img src="https://img.shields.io/github/repo-size/Lennolium/simple-useragent?label=Repo%20Size&color=yellow" alt="repo size" >
33+
<a href="https://pepy.tech/project/simple-useragent" >
34+
<img src="https://static.pepy.tech/badge/simple-useragent" alt="pypi downloads" >
3535
<a href="https://github.com/Lennolium/simple-useragent/blob/main/LICENSE" >
3636
<img src="https://img.shields.io/github/license/Lennolium/simple-useragent?label=License&color=blueviolet" alt="License" >
3737
<a></a> </a> </a> </a> </a> </a> </a> </a> </a>
@@ -236,7 +236,7 @@ Thank you so much for giving feedback, implementing features and improving the c
236236

237237
## Credits
238238

239-
Full credits are in the [acknowledgments](https://github.com/Lennolium/simple-useragent/blob/main/ACKNOWLEDGMENTS) file.
239+
Full credits are in the [ACKNOWLEDGMENTS](https://github.com/Lennolium/simple-useragent/blob/main/ACKNOWLEDGMENTS) file.
240240

241241
&nbsp;
242242

build.sh

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/bin/sh
2+
3+
# Script will exit if exit code is not 0.
4+
set -e
5+
6+
# Define colors for log.
7+
_info() { echo "\033[1m[INFO]\033[0m $1" ; }
8+
_ok() { echo "\033[32m[OK]\033[0m $1" ; }
9+
_error() { echo "\033[31m[ERROR]\033[0m $1" ; }
10+
_warn() { echo "\033[33m[WARN]\033[0m $1" ; }
11+
_logo() { echo "\033[1m $1\033[0m" ; }
12+
13+
14+
# Header
15+
echo ""
16+
echo ""
17+
_logo " █▌ ▀▀▀▀▀▀ ║█ ╫█ ▐█µ ▐█ ▄██▀▀██▌ ██ ▀└ █▌ ╒█▌ █µ █▌ "
18+
_logo " ▐█ ███▌ ██ ████ ██ ██ ╟█ ▐█ ▐█ ║█ ╫█ ║██▌ ╓███ "
19+
_logo " ██ ▀▀▀▀▀▀ ╒█Γ└██▓█ █▌ ██▓█▌▐█ ██ ██ ██ ██ ██ ███▀ ██ "
20+
_logo "┌▀ ██ ▀██ ║█ ╙██ └██ ╓██ █▌ ╒█▌ ██ ██ ╒█▌ ╙ ╒█Γ "
21+
_logo " -▀▀▀▀ ╝▀▀▀▀▀▀ ▀▀ ▀ ▀▀ ▀ ▀▀█▀▀ ╘▀▀▀▀▀ ╝▀ ▀██▀ ╝▀ ╝▀ "
22+
_logo " "
23+
_logo " P Y T H O N B U I L D S C R I P T "
24+
_logo " ------------------------------------------------------------------------- "
25+
echo ""
26+
echo ""
27+
28+
# Check if Python 3 is installed and install it if not.
29+
_info "Checking and installing requirements ..."
30+
if test ! "$(which python3)"; then
31+
_info "Python 3 is not installed! Installing with Homebrew ..."
32+
/bin/bash -c \
33+
"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
34+
brew update
35+
brew install python3
36+
else
37+
_ok "Python 3 is installed."
38+
fi
39+
40+
# Creating dist folder.
41+
mkdir -p dist/
42+
43+
# Delete the content of dist folder (to remove old .app builds).
44+
_info "Deleting old builds in /dist folder."
45+
rm -Rf dist/*
46+
47+
# Check if venv is created and do so if not.
48+
if ! [ -d "./venv" ] ; then
49+
_info "Creating virtual environment, so we do not pollute the system."
50+
python3 -m venv venv
51+
else
52+
_ok "Looks like a virtual environment is already created."
53+
fi
54+
55+
# Activate virtual environment, update and install requirements.
56+
_info "Installing and updating requirements."
57+
source venv/bin/activate
58+
pip install --upgrade pip
59+
python -m pip install pip-tools
60+
python -m pip install build twine
61+
pip install -r requirements.txt
62+
63+
# Save name of the package.
64+
package_directory=$(find src -mindepth 2 -maxdepth 2 -type f -name '__init__.py' -exec dirname {} \;)
65+
package_name=$(basename "$package_directory")
66+
67+
# Get the version of the package from __init__.py file.
68+
version=$(grep '__version__ =' "$package_directory/__init__.py" | sed -E 's/^.*"([^"]+)".*$/\1/')
69+
70+
# Override the version variable of setup.cfg with the version number of __init__.py.
71+
tmpfile=$(mktemp)
72+
sed "s/^version =.*/version = $version/" setup.cfg > "$tmpfile"
73+
mv "$tmpfile" setup.cfg
74+
_ok "Updated the version variable in 'setup.cfg' to $version"
75+
76+
# Build dist and verify.
77+
_info "Building the distribution files. This can take a while ..."
78+
if python -m build
79+
then
80+
twine check dist/*
81+
_ok "BUILD FINISHED!"
82+
else
83+
_error "BUILD FAILED!"
84+
exit 1
85+
fi
86+
87+
# Upload build to PyPI. Credentials are in '~.pypirc'.
88+
_info "Uploading built package to PyPI index."
89+
if twine upload -r pypi dist/*
90+
then
91+
_ok "UPLOAD FINISHED!"
92+
else
93+
_error "UPLOAD FAILED!"
94+
fi
95+
96+
# Generate sha256 hash files.
97+
_info "Generating sha256 checksum files..."
98+
cd dist || exit
99+
for file in *; do
100+
if [ -f "$file" ]; then
101+
shasum -a 256 "$file" > "$file.sha256"
102+
fi
103+
done
104+
105+
# Validate sha256 checksums.
106+
if sha256sum -c *.sha256; then
107+
_ok "Checksums are valid."
108+
_ok "BUILD AND UPLOAD COMPLETED!"
109+
else
110+
_error "Checksums are not valid."
111+
fi
112+
113+
# Cleanup egg files.
114+
cd .. || exit
115+
rm -rf "src/${package_name}.egg-info"
116+
117+
# Exit out of virtual environment.
118+
deactivate
119+
120+
_info "Exiting ..."
121+
exit 0

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = simple-useragent
3-
version = 0.1.0
3+
version = 0.1.1
44
author = Lennart Haack
55
author_email = info@lennolium.dev
66
license = GPL-3.0

src/simple_useragent/__init__.py

+36-7
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,55 @@
11
#!/usr/bin/env python3
22

33
"""
4-
__init__.py: Init file for simple_useragent package.
5-
64
Fetch real world user agents from the public API of the website
7-
'https://useragents.me/' for fetching up-to-date user agents for use in
5+
'https://useragents.me/' for getting up-to-date user agents for use in
86
a web scraping process to avoid bot detection.
97
108
You can either fetch random or usage weighted user agents. It caches
119
the user agents locally to avoid unnecessary API calls. The cached
1210
user agents are refreshed every 24 hours.
11+
12+
# Initialize the class to set custom settings:
13+
import simple_useragent as sua
14+
user_agents = sua.UserAgents(max_retries=5, timeout=10, ...)
15+
16+
# Fetch two random mobile user agent instances:
17+
user_agents.get(num=2, shuffle=True, mobile=True)
18+
>> [UserAgent('Mozilla/5.0 (iPhone ...'), UserAgent(
19+
'Mozilla/5.0 (iPhone; ...')]
20+
21+
# The functions have a convenience counterpart:
22+
obj = sua.get(num=1, force_cached=True)
23+
obj[0].string >> 'Mozilla/5.0 (Windows ...'
24+
obj[0].os >> 'Windows'
25+
26+
# Fetch the 3 most common desktop user agents as str in a list:
27+
sua.get_list(num=3)
28+
>> ['Mozilla/5.0 (Windows ...', '...', '...']
29+
30+
# Get all desktop and mobile user agents in a dict sorted by usage:
31+
sua.get_dict()
32+
>> {'desktop': ['Mozilla/5.0 (Windows ...', '...'],
33+
'mobile': ['Mozilla/5.0 (Android ...', '...']}
34+
35+
# Parse single user agent string and create a UserAgent object.
36+
ua = sua.UserAgent('Mozilla/5.0 (Windows, Chrome ...')
37+
ua.browser >> 'Chrome'
38+
ua.browser_version >> '91'
39+
40+
# Parse a single user agent string and create UserAgent object.
41+
sua.parse('Mozilla/5.0 (iPhone, Safari ...')
42+
>> UserAgent('Mozilla/5.0 (iPhone, Safari ...')
1343
"""
1444

1545
# Header.
1646
__author__ = "Lennart Haack"
1747
__email__ = "simple-useragent@lennolium.dev"
1848
__license__ = "GNU GPLv3"
19-
__version__ = "0.1.0"
20-
__date__ = "2024-01-31"
49+
__version__ = "0.1.1"
50+
__date__ = "2024-02-08"
2151
__status__ = "Development"
2252
__github__ = "https://github.com/Lennolium/simple-useragent"
2353

2454
# Imports.
25-
from simple_useragent.core import (UserAgents, UserAgent, get_dict, get_list,
26-
get, parse)
55+
from .core import UserAgents, UserAgent, get_dict, get_list, get, parse

0 commit comments

Comments
 (0)