Agent   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 22
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A post() 0 2 1
A set_user_agent() 0 4 1
A __init__() 0 4 1
A get_header() 0 2 1
A get() 0 2 1
A set_header() 0 2 1
1
from types import SimpleNamespace
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
3
import requests
4
5
6
UserAgent = SimpleNamespace(
0 ignored issues
show
Coding Style Naming introduced by
The name UserAgent does not conform to the constant naming conventions ((([A-Z_][A-Z0-9_]*)|(__.*__))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
7
    aol='Mozilla/4.0 (compatible; MSIE 4.01; AOL 4.0; Windows 95)',
8
    ie='Mozilla/4.0 (compatible; MSIE 4.01; Windows 95)',
9
    chrome='Mozilla/5.0 (Windows NT 6.1) AppleWebKit/530.10 (KHTML, like Gecko) Chrome/ Safari/530.5',
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (102/90).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
10
    safari='Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit (KHTML, like Gecko)',
11
    firefox='Mozilla/5.0 (Windows 95; en-US; rv:1.8.1.13) Gecko/20080313 Firefox',
12
    ios='mozilla/5.0 (iphone; cpu iphone os 8_0_0 like mac os x) applewebkit/537.51.1 (KHTML, like Gecko) version/7.0 mobile/11a501 safari/9537.53',
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (148/90).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
13
    android='Mozilla/5.0 (Linux; U; Android 2.3; en-us) AppleWebKit/999+ (KHTML, like Gecko) Safari/999.9'
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (106/90).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
14
)
15
16
17
class Agent:
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
18
    def __init__(self, user_agent='chrome'):
19
        self.session = requests.session()
20
        self.user_agent = user_agent
21
        self.set_user_agent(self.user_agent)
22
23
    def set_header(self, params):
24
        self.session.headers.update(params)
25
26
    def get_header(self, name):
27
        return self.session.headers[name]
28
29
    def get(self, url):
30
        return self.session.get(url)
31
32
    def post(self, url, **kwargs):
33
        return self.session.post(url, **kwargs)
34
35
    def set_user_agent(self, agent):
36
        agent_string = getattr(UserAgent, agent)
37
        params = {'User-Agent': agent_string}
38
        self.set_header(params)
39