Skip to content

Commit

Permalink
v2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
deedy5 committed Feb 18, 2024
1 parent c7c4c42 commit 243742b
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 220 deletions.
20 changes: 7 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Python >= 3.8](https://img.shields.io/badge/python->=3.6-red.svg)](https://www.python.org/downloads/) [![](https://badgen.net/github/release/deedy5/fake_traffic)](https://github.com/deedy5/fake_traffic/releases) [![](https://badge.fury.io/py/fake-traffic.svg)](https://pypi.org/project/fake-traffic)
# fake_traffic
Imitating an Internet user by mimicking popular web traffic (internet traffic generator).
Internet traffic generator.

---
### Install
Expand All @@ -20,14 +20,10 @@ CLI examples:
```python3
# user located in Turkey, who speaks Kurdish and is interested in hot stories
fake_traffic -c tr -l ku-tr -ca h
# user located in Brazil, who speaks Portuguese and is interested in sports
fake_traffic -c br -l pt-br -ca s
# save logs into 'fake_traffic.log'
fake_traffic -c ru -l ru-ru -ca s -lf
# define wait times between requests
fake_traffic -c fr -l fr-fr -ca b -min_w 1 -max_w 100 -lf
# use none-headless mode
fake_traffic -c en -l en-us -ca t -nh -lf
fake_traffic -c en -l en-us -ca t -nh
```
---
### Simple usage
Expand All @@ -42,14 +38,12 @@ FakeTraffic(country='US', language='en-US").crawl()
from fake_traffic import FakeTraffic

ft = FakeTraffic(country='US', language='en-US', category='h', min_wait=1, max_wait=5, headless=True)
""" Imitating an Internet user by mimicking popular web traffic (internet traffic generator).
"""Internet traffic generator.
country = country code ISO 3166-1 Alpha-2 code (https://www.iso.org/obp/ui/),
language = country-language code ISO-639 and ISO-3166 (https://www.fincher.org/Utilities/CountryLanguageList.shtml),
category = сategory of interest of a user (defaults to 'h'):
'all' (all), 'b' (business), 'e' (entertainment),
'm' (health), 's' (sports), 't' (sci/tech), 'h' (top stories);
min_wait = minimal delay between requests (defaults to 1),
max_wait = maximum delay between requests (defaults to 10),
headless = True/False (defaults to True).
"""
ft.crawl()
Expand Down Expand Up @@ -91,11 +85,11 @@ Country | Language | Function |
France | French | `FakeTraffic(country="FR", language="fr-FR")` |
Germany | German | `FakeTraffic(country="DE", language="de-DE", category='b')` |
India | English | `FakeTraffic(country="IN", language="en-IN", category='all')` |
India | Hindi | `FakeTraffic(country="IN", language="hi-IN", max_wait=10)` |
India | Hindi | `FakeTraffic(country="IN", language="hi-IN")` |
Russia | English | `FakeTraffic(country="RU", language="en-US", category='b', headless=False)` |
Russia | Russian | `FakeTraffic(country="RU", language="ru-RU", min_wait=0.5, max_wait=3)` |
Brazil | Portuguese | `FakeTraffic(country="BR", language="pt-BR", category='s', threads=2, max_wait=60)` |
Russia | Russian | `FakeTraffic(country="RU", language="ru-RU")` |
Brazil | Portuguese | `FakeTraffic(country="BR", language="pt-BR", category='s')` |
United Kingdom | English | `FakeTraffic(country="GB", language="en-GB")` |
United States | English | `FakeTraffic(country="US", language="en-US", min_wait=60, max_wait=300)` |
United States | English | `FakeTraffic(country="US", language="en-US")` |
United States | Hebrew Israel | `FakeTraffic(country="US", language="he-IL")` |

8 changes: 7 additions & 1 deletion fake_traffic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
import logging

from .fake_traffic import FakeTraffic
from .version import __version__
from .version import __version__

# A do-nothing logging handler
# https://docs.python.org/3.3/howto/logging.html#configuring-logging-for-a-library
logging.getLogger("fake_traffic").addHandler(logging.NullHandler())
35 changes: 5 additions & 30 deletions fake_traffic/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
from .fake_traffic import FakeTraffic


parser = argparse.ArgumentParser(
description="fake_traffic. Imitating an Internet user by mimicking popular web traffic (internet traffic generator)."
)
parser = argparse.ArgumentParser(description="Internet traffic generator")
parser.add_argument(
"-c",
"--country",
Expand All @@ -29,20 +27,6 @@
choices=["all", "b", "e", "m", "s", "t", "h"],
required=False,
)
parser.add_argument(
"-min_w",
"--min_wait",
default=1,
help="default=1. Minimum wait time between requests.",
required=False,
)
parser.add_argument(
"-max_w",
"--max_wait",
default=10,
help="default=10. Maximum wait time between requests.",
required=False,
)
parser.add_argument(
"-nh",
"--no-headless",
Expand All @@ -51,16 +35,9 @@
help="Run the browser in non-headless mode",
required=False,
)
parser.add_argument(
"-ll",
"--logging_level",
default="INFO",
help="logging level. default=INFO",
required=False,
)
parser.add_argument(
"-lf",
"--logging_file",
"--logfile",
action="store_true",
help="save the log into 'fake_traffic.log'",
required=False,
Expand All @@ -69,29 +46,27 @@

# logging
logging.basicConfig(
level=args.logging_level,
level=logging.INFO,
format="%(asctime)s | %(levelname)s | %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
force=True,
handlers=[logging.FileHandler("fake_traffic.log"), logging.StreamHandler()]
if args.logging_file
if args.logfile
else [logging.StreamHandler()],
)

country = args.country.upper()
language_split = args.language.split("-")
language = f"{language_split[0]}-{language_split[1].upper()}"
logging.info(
f"Run crawl with: {country=}, {language=}, category={args.category} min_w={args.min_wait}, max_w={args.max_wait}, headless={args.headless}, logging_level={args.logging_level}, logging_file={args.logging_file}"
f"Run crawl with: {country=}, {language=}, category={args.category}, headless={args.headless}, logfile={args.logfile}"
)


fake_traffic = FakeTraffic(
country=country,
language=language,
category=args.category,
min_wait=int(args.min_wait),
max_wait=int(args.max_wait),
headless=args.headless,
)
fake_traffic.crawl()
Loading

0 comments on commit 243742b

Please sign in to comment.