pythonanywhere-core 0.2.6__tar.gz → 0.2.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pythonanywhere-core
3
- Version: 0.2.6
3
+ Version: 0.2.7
4
4
  Summary: API wrapper for programmatic management of PythonAnywhere services.
5
5
  License: MIT
6
6
  Keywords: pythonanywhere,api,cloud,web hosting
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "pythonanywhere-core"
3
- version = "0.2.6"
3
+ version = "0.2.7"
4
4
  description = "API wrapper for programmatic management of PythonAnywhere services."
5
5
  authors = ["PythonAnywhere <developers@pythonanywhere.com>"]
6
6
  license = "MIT"
@@ -0,0 +1 @@
1
+ __version__ = "0.2.7"
@@ -0,0 +1,32 @@
1
+ import getpass
2
+
3
+ from pythonanywhere_core.base import call_api, get_api_endpoint
4
+ from pythonanywhere_core.exceptions import PythonAnywhereApiException
5
+
6
+
7
+ class CPU:
8
+ """Interface for PythonAnywhere CPU resources API.
9
+
10
+ Uses `pythonanywhere_core.base` :method: `get_api_endpoint` to
11
+ create url, which is stored in a class variable `CPU.base_url`,
12
+ then calls `call_api` with appropriate arguments to execute CPU
13
+ resource actions.
14
+
15
+ Methods:
16
+ - :meth:`CPU.get_cpu_usage`: Get current CPU usage information.
17
+ """
18
+
19
+ def __init__(self):
20
+ self.base_url = get_api_endpoint(username=getpass.getuser(), flavor="cpu")
21
+
22
+ def get_cpu_usage(self):
23
+ """Get current CPU usage information.
24
+
25
+ :returns: dictionary with CPU usage information including daily limit,
26
+ total usage, and next reset time
27
+ :raises PythonAnywhereApiException: if API call fails
28
+ """
29
+ response = call_api(url=self.base_url, method="GET")
30
+ if not response.ok:
31
+ raise PythonAnywhereApiException(f"GET to {self.base_url} failed, got {response}:{response.text}")
32
+ return response.json()
@@ -1,7 +1,5 @@
1
- import os
2
1
  import getpass
3
- from snakesay import snakesay
4
- from textwrap import dedent
2
+
5
3
 
6
4
  from pythonanywhere_core.base import call_api, get_api_endpoint
7
5
  from pythonanywhere_core.exceptions import DomainAlreadyExistsException, PythonAnywhereApiException
@@ -1 +0,0 @@
1
- __version__ = "0.2.6"