Compare commits
19 Commits
4e5642a83b
...
sev-martin
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
292fadca5c | ||
| 621bdc3a2d | |||
|
|
23091bd7ff | ||
|
|
5d5d48e13e | ||
|
|
d17efbb2f2 | ||
| f77082d6cf | |||
| 9ae58a0f4f | |||
| bf12d1e5d4 | |||
| 278eee7246 | |||
|
|
2bb42ab8f6 | ||
|
|
7d55d258ac | ||
|
|
a09846193d | ||
|
|
20c041878d | ||
|
|
ae8cf7247d | ||
|
|
342a45a4f2 | ||
|
|
b09af3ea95 | ||
|
|
79fa977d72 | ||
|
|
6304fb4def | ||
|
|
138e6b30d7 |
0
ThisIsANewFile.txt
Normal file
0
ThisIsANewFile.txt
Normal file
2
python/EXERCISE.md
Normal file
2
python/EXERCISE.md
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
L'étudiant.e s'engage dans une recherche créative en faisant un commentaire, une réflexion ou un detournement des plateformes culturelles, ou des débats politiques, qui sont médiatisés numériquement (par example en ligne). Cet exercice doit avoir un élément artistique et faire appel à Python en tout, ou en partie dans son exécution. Vous pouvez consulter le matériel pertinent de la classe python, tel que les diapositives de présentation, les exemples de code et les références de tutoriels, à l'adresse suivante:
|
||||||
|
https://git.erg.school/P039/art_num_2024/src/branch/main/python
|
||||||
@@ -1 +1,37 @@
|
|||||||
git repo for art num
|
## Python course
|
||||||
|
|
||||||
|
### install pip3 or pip
|
||||||
|
Windows/Linux: [Installation](https://pip.pypa.io/en/stable/installation/)
|
||||||
|
MacOS: [Install Homebrew](https://brew.sh/).
|
||||||
|
After installation you may need to add homebrew to your PATH. Exectute the code, line by line, from the messages at the end of the homebrew installation in your terminal. You may also read how to do it [here](https://usercomp.com/news/1130946/add-homebrew-to-path).
|
||||||
|
Verify brew is installed with `brew --version`. If not errors, then install pip with `brew install pip`.
|
||||||
|
|
||||||
|
Depending on your system, you may have pip or pip3. Execute `pip --version` or `pip3 --version` and see which one works for you.
|
||||||
|
|
||||||
|
### virtualenv
|
||||||
|
Windows/Linux: [Installation](https://virtualenv.pypa.io/en/latest/installation.html)
|
||||||
|
MacOS: Execute `brew install virtualenv`
|
||||||
|
How to use it for all systems -> [User Guide](https://virtualenv.pypa.io/en/latest/user_guide.html)
|
||||||
|
|
||||||
|
### videogrep
|
||||||
|
tutorial: https://lav.io/notes/videogrep-tutorial/
|
||||||
|
code: https://github.com/antiboredom/videogrep/tree/master
|
||||||
|
videos: https://antiboredom.github.io/videogrep/
|
||||||
|
|
||||||
|
|
||||||
|
### python tutorials here
|
||||||
|
[python basics](./introduction/README.md)
|
||||||
|
[python scraping](./scrape/README.md)
|
||||||
|
|
||||||
|
### python tutorials online
|
||||||
|
RealPython => need to create free account
|
||||||
|
[Work with python from the terminal or with a code editor](https://realpython.com/interacting-with-python/)
|
||||||
|
[Variables](https://realpython.com/python-variables/)
|
||||||
|
[User input from terminal/keyboard](https://realpython.com/python-keyboard-input/)
|
||||||
|
[if/ elif/ else](https://realpython.com/courses/python-conditional-statements/)
|
||||||
|
[Adding strings together](https://realpython.com/python-string-concatenation/)
|
||||||
|
[Data types](https://realpython.com/python-data-types/)
|
||||||
|
|
||||||
|
|
||||||
|
### artisitc references
|
||||||
|
[presentation - slides](./presentation-en.pdf)
|
||||||
|
|||||||
BIN
python/audio/opensource.mp4
Normal file
BIN
python/audio/opensource.mp4
Normal file
Binary file not shown.
BIN
python/audio/opensourcecut.mp4
Normal file
BIN
python/audio/opensourcecut.mp4
Normal file
Binary file not shown.
@@ -1,16 +1,14 @@
|
|||||||
## introduction
|
## introduction
|
||||||
|
|
||||||
```
|
```
|
||||||
variables
|
For variables --> see all scripts
|
||||||
list --> bisous.py programming.py
|
Working with lists --> see bisous.py programming.py
|
||||||
input --> bisous.py
|
For user input from terminal or keyboard --> see bisous.py
|
||||||
print
|
print
|
||||||
for loop --> bisous.py
|
for loop --> see bisous.py
|
||||||
conditional statements if/else/elif --> bisous.py
|
conditional statements if/else/elif --> see bisous.py
|
||||||
break --> bisous.py
|
break --> bisous.py
|
||||||
while loop --> missing.py
|
while loop --> see missing.py
|
||||||
dictionary
|
|
||||||
enumerate
|
|
||||||
return --> missing.py
|
|
||||||
random --> programming.py
|
|
||||||
function --> missing.py
|
function --> missing.py
|
||||||
|
random --> programming.py
|
||||||
```
|
```
|
||||||
|
|||||||
0
python/machine_learning/__init__.py
Normal file
0
python/machine_learning/__init__.py
Normal file
1
python/machine_learning/rnn-test.py
Normal file
1
python/machine_learning/rnn-test.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#copy code here
|
||||||
1
python/machine_learning/rnn.py
Normal file
1
python/machine_learning/rnn.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# copy here your code
|
||||||
BIN
python/presentation-en.pdf
Normal file
BIN
python/presentation-en.pdf
Normal file
Binary file not shown.
@@ -13,4 +13,12 @@ python get_images.py https://www.freepik.com/images
|
|||||||
Remplacez l’URL par le lien que vous souhaitez extraire.
|
Remplacez l’URL par le lien que vous souhaitez extraire.
|
||||||
**Remarque:** Le scraping doit être effectué de manière éthique, en respectant les règles du fichier robots.txt et les conditions d'utilisation du site.
|
**Remarque:** Le scraping doit être effectué de manière éthique, en respectant les règles du fichier robots.txt et les conditions d'utilisation du site.
|
||||||
|
|
||||||
|
### Beautiful soup
|
||||||
|
[INSTALL](https://beautiful-soup-4.readthedocs.io/en/latest/#installing-beautiful-soup)
|
||||||
|
[HOWTO](https://beautiful-soup-4.readthedocs.io/en/latest/#making-the-soup)
|
||||||
|
[WORK with HTML TAG](https://beautiful-soup-4.readthedocs.io/en/latest/#navigating-the-tree)
|
||||||
|
|
||||||
|
### Collage avec des images
|
||||||
|
[Make video with all same size images](https://pythonexamples.org/python-opencv-cv2-create-video-from-images/)
|
||||||
|
|
||||||
|
[Change images to same size then make a video](https://www.geeksforgeeks.org/python-create-video-using-multiple-images-using-opencv/)
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import random
|
||||||
|
import urllib
|
||||||
import requests
|
import requests
|
||||||
import time
|
import time
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
@@ -32,7 +34,16 @@ if not os.path.exists(save_folder):
|
|||||||
os.makedirs(save_folder)
|
os.makedirs(save_folder)
|
||||||
|
|
||||||
# Send GET request to the page
|
# Send GET request to the page
|
||||||
response = requests.get(input_url)
|
user_agents = [
|
||||||
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
|
||||||
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15',
|
||||||
|
'Mozilla/5.0 (iPhone; CPU iPhone OS 14_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.1',
|
||||||
|
]
|
||||||
|
headers = {
|
||||||
|
"User-Agent": random.choice(user_agents)
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.get(input_url, headers=headers)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
# Parse the HTML content with BeautifulSoup
|
# Parse the HTML content with BeautifulSoup
|
||||||
soup = BeautifulSoup(response.text, 'html.parser')
|
soup = BeautifulSoup(response.text, 'html.parser')
|
||||||
@@ -47,15 +58,16 @@ if response.status_code == 200:
|
|||||||
# Check if img_url is complete; if not, adjust it accordingly
|
# Check if img_url is complete; if not, adjust it accordingly
|
||||||
if not img_url.startswith("http"):
|
if not img_url.startswith("http"):
|
||||||
img_url = full_domain + "/" + img_url
|
img_url = full_domain + "/" + img_url
|
||||||
|
img_url = img_url.split("&")
|
||||||
|
img_url = img_url[0]
|
||||||
try:
|
try:
|
||||||
# Send request to the image URL
|
# Send request to the image URL
|
||||||
img_data = requests.get(img_url).content
|
img_data = requests.get(img_url, headers=headers).content
|
||||||
# Define file name and path
|
# Define file name and path
|
||||||
img_name = os.path.join(save_folder, f"image_{idx}.jpg")
|
img_name = os.path.join(save_folder, f"image_{idx}.jpg")
|
||||||
# Write image data to file
|
# Write image data to file
|
||||||
with open(img_name, 'wb') as handler:
|
with open(img_name, 'wb') as img_bytes:
|
||||||
handler.write(img_data)
|
img_bytes.write(img_data)
|
||||||
|
|
||||||
print(f"Downloaded {img_name}")
|
print(f"Downloaded {img_name}")
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|||||||
82
python/scrape/get_images_montreuil.py
Normal file
82
python/scrape/get_images_montreuil.py
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
import random
|
||||||
|
import urllib
|
||||||
|
import requests
|
||||||
|
import time
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import tldextract
|
||||||
|
|
||||||
|
# URL of the webpage with images
|
||||||
|
input_url = sys.argv[1]
|
||||||
|
|
||||||
|
# extract full domain
|
||||||
|
def split_domain_or_subdomain_and_path(url):
|
||||||
|
# Parse the URL
|
||||||
|
parsed_url = urlparse(url)
|
||||||
|
extracted = tldextract.extract(url)
|
||||||
|
|
||||||
|
# Build the full domain, including subdomain if present
|
||||||
|
if extracted.subdomain:
|
||||||
|
full_domain = f"{extracted.subdomain}.{extracted.domain}.{extracted.suffix}"
|
||||||
|
else:
|
||||||
|
full_domain = f"{extracted.domain}.{extracted.suffix}"
|
||||||
|
|
||||||
|
return "https://" + full_domain
|
||||||
|
|
||||||
|
full_domain = split_domain_or_subdomain_and_path(input_url)
|
||||||
|
print(f"Domain/Subdomain: {full_domain}")
|
||||||
|
|
||||||
|
# Folder to save images
|
||||||
|
save_folder = "downloaded_images"
|
||||||
|
if not os.path.exists(save_folder):
|
||||||
|
os.makedirs(save_folder)
|
||||||
|
|
||||||
|
# Send GET request to the page
|
||||||
|
#response = se.get(input_url)
|
||||||
|
user_agents = [
|
||||||
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
|
||||||
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15',
|
||||||
|
'Mozilla/5.0 (iPhone; CPU iPhone OS 14_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.1',
|
||||||
|
]
|
||||||
|
headers = {
|
||||||
|
"User-Agent": random.choice(user_agents)
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.get(input_url, headers=headers)
|
||||||
|
if response.status_code == 200:
|
||||||
|
# Parse the HTML content with BeautifulSoup
|
||||||
|
soup = BeautifulSoup(response.text, 'html.parser')
|
||||||
|
|
||||||
|
# Find all image tags
|
||||||
|
images = soup.find_all('img')
|
||||||
|
|
||||||
|
# Loop through image tags
|
||||||
|
for idx, img in enumerate(images):
|
||||||
|
img_url = img.get('src')
|
||||||
|
|
||||||
|
# Check if img_url is complete; if not, adjust it accordingly
|
||||||
|
if not img_url.startswith("http"):
|
||||||
|
img_url = full_domain + "/" + img_url
|
||||||
|
img_url = img_url.split("&")
|
||||||
|
img_url = img_url[0]
|
||||||
|
print(img_url)
|
||||||
|
try:
|
||||||
|
print(img_url)
|
||||||
|
# Send request to the image URL
|
||||||
|
img_data = requests.get(img_url, headers=headers).content
|
||||||
|
# Define file name and path
|
||||||
|
img_name = os.path.join(save_folder, f"image_{idx}.jpg")
|
||||||
|
# Write image data to file
|
||||||
|
with open(img_name, 'wb') as img_bytes:
|
||||||
|
img_bytes.write(img_data)
|
||||||
|
img_bytes.write(requests.get(img_url).content)
|
||||||
|
|
||||||
|
print(f"Downloaded {img_name}")
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Failed to download {img_url}. Error: {e}")
|
||||||
|
else:
|
||||||
|
print("Failed to retrieve the page.")
|
||||||
BIN
python/videos/queercut.mp4
Normal file
BIN
python/videos/queercut.mp4
Normal file
Binary file not shown.
Reference in New Issue
Block a user