• azure,  Python

    Function app First function Python Linux, hm, must upload code from local The Azure Functions extension for Visual Studio Code. Azure icon click it, takes time Select a language for your function project: Choose Python.Select a Python alias to create a virtual environment: Choose the location of your Python interpreter. If the location isn’t shown, type in the full path to your Python binary.Select a template for your project’s first function: Choose HTTP trigger.Provide a function name: Type HttpExample.Authorization level: Choose Anonymous, which enables anyone to call your function endpoint. To learn about authorization level, see Authorization keys.Select how you would like to open your project: Choose Add to workspace.…

    Comments Off on Function app
  • azure,  Python

    Azure SDK Pyhon Python Guidelines: Introduction: Design principlesIdiomaticConsistentApproachableDiagnosableDependablePython Design Principles:–PEP 20 — The Zen of Python, import this General Guidelines: Gitub: Supported python versions:Code style: Naming conventions: service_client = ServiceClient() service_client.list_things() def do_something(): class ThisIsCorrect(object): pass MAX_SIZE = 4711 Method signatures: DO NOT use, static, do not use get set, use properties class GoodThing(object): DO specify the parameter name when calling methods with more than two required positional parameters. def foo(a, b, c): pass def bar(d, e): pass Yes: foo(a=1, b=2, c=3) bar(1, 2) bar(e=3, d=4) No: foo(1, 2, 3) Public vs “private”: yes- azure.exampleservice._some_internal_module no – azure.exampleservice.some_internal_module Types (or not): DO prefer structural subtyping and protocols…

    Comments Off on Azure SDK Pyhon
  • Docker,  linux,  Python

    Docker-compose ubuntu

    Install it from here, the two first lines curl -fsSL -o sh docker –version Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration. To learn more about all the features of Compose, see the list of features. Compose works in all environments: production, staging, development, testing, as well as CI workflows. You can learn more about each case in Common Use Cases. Now lets create a simpel python module and run it with docker and portainer.…

    Comments Off on Docker-compose ubuntu
  • PEP8,  Python

    PEP 8

    Programming Recommendations Use is not operator rather than not … is. While both expressions are functionally identical, the former is more readable and preferred. Always use a def statement instead of an assignment statement that binds a lambda expression directly to an identifier. Derive exceptions from Exception rather than BaseException. Direct inheritance from BaseException is reserved for exceptions where catching them is almost always the wrong thing to do. Design exception hierarchies based on the distinctions that code catching the exceptions is likely to need, rather than the locations where the exceptions are raised. Aim to answer the question “What went wrong?” programmatically, rather than only stating that “A…

  • Python,  VSC

    Python debugging in VS Code

    Debugging 101 We need VSC, Python extension and a launch.json with the minimum of integrated and external. Click on the Debugging icon in the Activity Bar to bring up the Debug view. Then click on the gear icon to configure a launch.json file, select Launch for the environment. (Some .Net software will be installed) Select the py file to open the configuration or launch.json The launch.json Debug->Open configurations For basic Python debugging of files, you will only need the following configuration: Ok, let’s run a script and test it. Start Debugging. 1 Open your Python file in VS Code. 2 Go to the Debug view, select the Start Debugging…

    Comments Off on Python debugging in VS Code
  • Python

    Python, lxml and Xpath Read a file with xml, convert it to a string from bytes: pip install lxml from lxml import etree as et Make dictionary (duplicate keys, get atr) result: Code: def xml_to_dict(xmlfile): msg = {} count = 1 with open(xmlfile) as r: xml = print(type(xml)) parser = et.XMLParser(recover=True, collect_ids=True) root = et.fromstring(bytes(xml, encoding="utf-8"), parser) x = root.xpath("//*")# get all #x = root.xpath("//*[@id]")# get all for y in x: key = et.QName(y).localname value = y.text i = y.attrib.get("id") if i is not None: print(i) if key in msg: key = key + str(count) count += 1 tmp = {key:value} msg.update(tmp) for k, v in msg.items(): print(k, ":", v)

    Comments Off on Python, lxml and Xpath
  • linux,  Python

    Python as systemctl service This is an easy and not enough tested script, you may also enable it to start at boot. Read about systemctl: So create a file in /lib/systemd/system touch python_service.service sudo nano python_service.service run the script with (when it is done and has no erros): This is my test script: It prints service and writes to a file: sudo systemctl start python_service.service sudo systemctl status python_service.service sudo systemctl stop python_service.service Now lets clean the file and run it as a service: sudo systemctl start python_service.service Now lets stop it and check status, and check the file And the file is full, nice, but the dir is now /…

    Comments Off on Python as systemctl service
  • linux,  Python,  Sql

    MariaDb linux Python ORM MariaDB is an open source, multi-threaded relational database management system, backward compatible replacement for MySQL. It is maintained and developed by the MariaDB Foundation including some of the original developers of the MySQL. sudo apt update sudo apt install mariadb-server sudo mysql -V sudo systemctl status mariadb Run the mysql_secure_installation command to improve the security of the MariaDB installation: sudo mysql_secure_installation The script will prompt you to set up the root user password, remove the anonymous user, restrict root user access to the local machine and remove the test database. At the end the script will reload the privilege tables ensuring that all changes take effect immediately. All…

    Comments Off on MariaDb linux Python ORM
  • Python,  Python Networking and Security

    Python for Cyber Security additional resources to learn

    The Cyber Defenders Program: So the plan is to do the second and third resource first and then move to the next. The first one is a course so…. Second, skip the most of the basic, repeat some from automating the boring stuff: Chapter 5 – Dictionaries and Structuring Data = checkChapter 10 – Debugging = checkChapter 14 – Working with CSV Files (no linux on windows ok) and JSON Data = checkChapter 15 – Keeping Time, Scheduling Tasks, and Launching Programs = in progressChapter 17 – Manipulating Images Third, go through all and read, Cracking Codes with Python: Next are the rest of the lessons: Python…

    Comments Off on Python for Cyber Security additional resources to learn