quarta-feira, 19 de janeiro de 2022

#Creating a virtual environment

 #Creating a virtual environment
"""
venv — Creation of virtual environments
Python.org: https://docs.python.org/3/library/venv.html

How to install virtualenv:
Source: https://gist.github.com/Geoyi/d9fab4f609e9f75941946be45000632b

f3l1p@VsTr:~$ sudo apt-get install python3-pip
f3l1p@VsTr:~$ sudo pip3 install virtualenv

Python Tutorial: VENV (Mac & Linux) - How to Use Virtual Environments with the Built-In venv Module: Source: https://youtu.be/Kg1Yvry_Ydk

Displays the packages installed by pip3:
f3l1p@VsTr:~$ pip3 list

Creation of virtual environments is done by executing the command venv:
f3l1p@VsTr:~$ python3 -m venv ~/Venv/venv1

==============   Notice of system   ========================
The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.

    apt-get install python3-venv

You may need to use sudo with that command.  After installing the python3-venv
package, recreate your virtual environment.

Failing command: ['/home/f3l1p/Venv/Venv1/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']
============================================================

Here in Ubuntu it can also be used to create a new environment the command:
f3l1p@VsTr:~$ virtualenv ~/Venv/Venv1
created virtual environment CPython3.6.9.final.0-64 in 798ms
  creator CPython3Posix(dest=/home/f3l1p/Venv/Venv2, clear=False, no_vcs_ignore=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/f3l1p/.local/share/virtualenv)
    added seed packages: pip==21.3.1, setuptools==59.6.0, wheel==0.37.1
  activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator

Active your virtual environment:
f3l1p@VsTr:~$ source ~/Venv/Venv1/bin/activate
(Venv1) f3l1p@VsTr:~$
(The Venv name before the username in parentheses means that it is already inside the virtual environment.  (Venv1) f3l1p@VsTr:~$   )

To deactivate:
(Venv1) f3l1p@VsTr:~$ deactivate

"""

 


======

12. Virtual Environments and Packages
12.1. Introduction

Python applications will often use packages and modules that don’t come as part of the standard library. Applications will sometimes need a specific version of a library, because the application may require that a particular bug has been fixed or the application may be written using an obsolete version of the library’s interface.

This means it may not be possible for one Python installation to meet the requirements of every application. If application A needs version 1.0 of a particular module but application B needs version 2.0, then the requirements are in conflict and installing either version 1.0 or 2.0 will leave one application unable to run.

The solution for this problem is to create a virtual environment, a self-contained directory tree that contains a Python installation for a particular version of Python, plus a number of additional packages.

Different applications can then use different virtual environments. To resolve the earlier example of conflicting requirements, application A can have its own virtual environment with version 1.0 installed while application B has another virtual environment with version 2.0. If application B requires a library be upgraded to version 3.0, this will not affect application A’s environment.
Continue reading at:
https://docs.python.org/3/tutorial/venv.html?highlight=pip%20requests

# Pypi: Requests

"""
Python Requests Tutorial: Request Web Pages, Download Images, POST Data, Read JSON, and More
https://youtu.be/tb8gHvYlCFs

requests 2.27.1
https://pypi.org/project/requests/

Installing:
(Venv1) f3l1p@VsTr:~$ pip install requests

(Venv1) f3l1p@VsTr:~$ nano resquest.py

====== resquest.py ======
import requests

r = requests.get('https://marocero2016.blogspot.com/')

print(r.text)
======      ======

(Venv1) f3l1p@VsTr:~$ alias py="python3"

(Venv1) f3l1p@VsTr:~$ py request.py


"""


import requests

r = requests.get('https://marocero2016.blogspot.com/')

txt = r.text

c = 0
http = ""
lista = ""
print(len(txt))

while c < len(txt) - 4:
    if txt[c] + txt[c+1] + txt[c+2] + txt[c+3] + txt[c+4] == "http:":
        #print(c, txt[c] + txt[c+1] + txt[c+2] + txt[c+3] + txt[c+4])
        if txt[c+7] + txt[c+8] + txt[c+9] + txt[c+10] + txt[c+11] != "schem":

            while c < len(txt) -4:
                if txt[c] == "'" or txt[c] == '"':
                    break
                http += txt[c]
                c += 1
            lista += http + "\n"
            http = ""
            print(lista)
    c += 1

print(lista)




Nenhum comentário:

Postar um comentário