jeduardogruiz
commited on
Commit
•
17de07a
1
Parent(s):
4da5712
Rename Readme_robots_1.py to aplicación.py
Browse files- Readme_robots_1.py +0 -199
- aplicación.py +82 -0
Readme_robots_1.py
DELETED
@@ -1,199 +0,0 @@
|
|
1 |
-
import random
|
2 |
-
|
3 |
-
def generate_robot_data():
|
4 |
-
"""
|
5 |
-
Generates random robot data.
|
6 |
-
"""
|
7 |
-
return {
|
8 |
-
"robot_id": random.randint(1, 100),
|
9 |
-
"model": random.choice(["v1", "v2", "v3"]),
|
10 |
-
"battery_level": random.uniform(0, 100),
|
11 |
-
"location": (random.randint(0, 100), random.randint(0, 100))
|
12 |
-
}
|
13 |
-
|
14 |
-
def route_command(robot_data, command):
|
15 |
-
"""
|
16 |
-
Routes a command to a robot.
|
17 |
-
"""
|
18 |
-
print(f"Routing command '{command}' to robot with ID {robot_data['robot_id']}...")
|
19 |
-
|
20 |
-
def main():
|
21 |
-
"""
|
22 |
-
Generates robot data and routes a command to a robot.
|
23 |
-
"""
|
24 |
-
robot_data = generate_robot_data()
|
25 |
-
command = "Move to new location"
|
26 |
-
|
27 |
-
route_command(robot_data, command)
|
28 |
-
|
29 |
-
if __name__ == "__main__":
|
30 |
-
main()
|
31 |
-
##lista de Robots del demonio
|
32 |
-
##1
|
33 |
-
import random
|
34 |
-
|
35 |
-
def generate_robot_data():
|
36 |
-
"""
|
37 |
-
Generates random robot data.
|
38 |
-
"""
|
39 |
-
return {
|
40 |
-
"robot_id": random.randint(1, 100),
|
41 |
-
"model": random.choice(["v1", "v2", "v3"]),
|
42 |
-
"battery_level": random.uniform(0, 100),
|
43 |
-
"location": (random.randint(0, 100), random.randint(0, 100))
|
44 |
-
}
|
45 |
-
|
46 |
-
def extract_values(robot_data):
|
47 |
-
"""
|
48 |
-
Extracts values from robot data.
|
49 |
-
"""
|
50 |
-
robot_id = robot_data["robot_id"]
|
51 |
-
model = robot_data["model"]
|
52 |
-
battery_level = robot_data["battery_level"]
|
53 |
-
location_x, location_y = robot_data["location"]
|
54 |
-
|
55 |
-
return robot_id, model, battery_level, location_x, location_y
|
56 |
-
|
57 |
-
def main():
|
58 |
-
"""
|
59 |
-
Generates robot data, extracts values, and prints them.
|
60 |
-
"""
|
61 |
-
robot_data = generate_robot_data()
|
62 |
-
robot_id, model, battery_level, location_x, location_y = extract_values(robot_data)
|
63 |
-
|
64 |
-
print("Robot 1 Values:")
|
65 |
-
print(f"ID: {robot_id}")
|
66 |
-
print(f"Model: {model}")
|
67 |
-
print(f"Battery Level: {battery_level:.2f}%")
|
68 |
-
print(f"Location: ({location_x}, {location_y})")
|
69 |
-
|
70 |
-
if __name__ == "__main__":
|
71 |
-
main()
|
72 |
-
Robot 1 Values:
|
73 |
-
ID: 43
|
74 |
-
Model: v2
|
75 |
-
Battery Level: 73.42%
|
76 |
-
Location: (14, 87)
|
77 |
-
##2
|
78 |
-
import random
|
79 |
-
|
80 |
-
def generate_robot_data():
|
81 |
-
"""
|
82 |
-
Generates random robot data.
|
83 |
-
"""
|
84 |
-
return {
|
85 |
-
"robot_id": random.randint(1, 100),
|
86 |
-
"model": random.choice(["v1", "v2", "v3"]),
|
87 |
-
"battery_level": random.uniform(0, 100),
|
88 |
-
"location": (random.randint(0, 100), random.randint(0, 100))
|
89 |
-
}
|
90 |
-
|
91 |
-
def extract_values(robot_data):
|
92 |
-
"""
|
93 |
-
Extracts values from robot data.
|
94 |
-
"""
|
95 |
-
robot_id = robot_data["robot_id"]
|
96 |
-
model = robot_data["model"]
|
97 |
-
battery_level = robot_data["battery_level"]
|
98 |
-
location_x, location_y = robot_data["location"]
|
99 |
-
|
100 |
-
return robot_id, model, battery_level, location_x, location_y
|
101 |
-
|
102 |
-
def main():
|
103 |
-
"""
|
104 |
-
Generates robot data, extracts values, and prints them.
|
105 |
-
"""
|
106 |
-
robot_data = generate_robot_data()
|
107 |
-
robot_id, model, battery_level, location_x, location_y = extract_values(robot_data)
|
108 |
-
|
109 |
-
print("Robot 1 Values:")
|
110 |
-
print(f"ID: {robot_id}")
|
111 |
-
print(f"Model: {model}")
|
112 |
-
print(f"Battery Level: {battery_level:.2f}%")
|
113 |
-
print(f"Location: ({location_x}, {location_y})")
|
114 |
-
##loveMe
|
115 |
-
if __name__ == "__main__":
|
116 |
-
main()
|
117 |
-
Robot 1 Values:
|
118 |
-
ID: 43
|
119 |
-
Model: v2
|
120 |
-
Battery Level: 73.42%
|
121 |
-
Location: (14, 87)
|
122 |
-
|
123 |
-
##3
|
124 |
-
import os
|
125 |
-
import pkg_resources
|
126 |
-
|
127 |
-
class InstallerBot:
|
128 |
-
"""
|
129 |
-
A bot that ensures that every file in a package is installed.
|
130 |
-
"""
|
131 |
-
|
132 |
-
def __init__(self, package_name):
|
133 |
-
"""
|
134 |
-
Initializes the bot with a package name.
|
135 |
-
"""
|
136 |
-
self.package_name = package_name
|
137 |
-
|
138 |
-
def check_installed(self):
|
139 |
-
"""
|
140 |
-
Checks if every file in the package is installed.
|
141 |
-
"""
|
142 |
-
try:
|
143 |
-
package = pkg_resources.get_distribution(self.package_name)
|
144 |
-
for file in package.as_requirement().files:
|
145 |
-
file_path = os.path.join(package.location, file)
|
146 |
-
if not os.path.exists(file_path):
|
147 |
-
print(f"File {file_path} not found.")
|
148 |
-
except pkg_resources.DistributionNotFound:
|
149 |
-
print(f"Package {self.package_name} not found.")
|
150 |
-
|
151 |
-
if __name__ == "__main__":
|
152 |
-
bot = InstallerBot("Eduardo_ruiz-Mixtral_eter")
|
153 |
-
bot.check_installed()
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
##4
|
158 |
-
import os
|
159 |
-
import subprocess
|
160 |
-
import sys
|
161 |
-
import pkg_resources
|
162 |
-
|
163 |
-
class ScaryRobot:
|
164 |
-
"""
|
165 |
-
A "scary" robot that shuts down the computer and uninstalls the `Eduardo_ruiz-Mixtral_eter` package.
|
166 |
-
"""
|
167 |
-
|
168 |
-
def __init__(self):
|
169 |
-
"""
|
170 |
-
Initializes the robot.
|
171 |
-
"""
|
172 |
-
self.package_name = "Eduardo_ruiz-Mixtral_eter"
|
173 |
-
|
174 |
-
def shutdown(self):
|
175 |
-
"""
|
176 |
-
Shuts down the computer.
|
177 |
-
"""
|
178 |
-
os.system("shutdown /s /t 1")
|
179 |
-
|
180 |
-
def uninstall_package(self):
|
181 |
-
"""
|
182 |
-
Uninstalls the `Eduardo_ruiz-Mixtral_eter` package.
|
183 |
-
"""
|
184 |
-
try:
|
185 |
-
pkg_resources.get_distribution(self.package_name).resolve()
|
186 |
-
subprocess.check_call([sys.executable, "-m", "pip", "uninstall", "-y", self.package_name])
|
187 |
-
except pkg_resources.DistributionNotFound:
|
188 |
-
print(f"Package {self.package_name} not found.")
|
189 |
-
|
190 |
-
def scare(self):
|
191 |
-
"""
|
192 |
-
Shuts down the computer and uninstalls the `Eduardo_ruiz-Mixtral_eter` package.
|
193 |
-
"""
|
194 |
-
self.shutdown()
|
195 |
-
self.uninstall_package()
|
196 |
-
|
197 |
-
if __name__ == "__main__":
|
198 |
-
robot = ScaryRobot()
|
199 |
-
robot.scare()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
aplicación.py
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import config, time, ccxt
|
2 |
+
from flask import Flask, render_template, request, flash, redirect, url_for
|
3 |
+
from werkzeug.urls import url_parse
|
4 |
+
from web3 import Web3
|
5 |
+
import os
|
6 |
+
import requests
|
7 |
+
from dotenv import load_dotenv
|
8 |
+
load_dotenv()
|
9 |
+
|
10 |
+
app = Flask(__name__, template_folder="templates")
|
11 |
+
app.config['SECRET_KEY'] = 'somerandomstring'
|
12 |
+
|
13 |
+
w3 = Web3(Web3.HTTPProvider(os.getenv("INFURA_URL")))
|
14 |
+
|
15 |
+
def get_ethereum_price():
|
16 |
+
binance = ccxt.binance()
|
17 |
+
ethereum_price = binance.fetch_ticker('ETH/USDC')
|
18 |
+
|
19 |
+
return ethereum_price
|
20 |
+
|
21 |
+
@app.route("/")
|
22 |
+
def index():
|
23 |
+
eth = w3.eth
|
24 |
+
|
25 |
+
ethereum_price = get_ethereum_price()
|
26 |
+
|
27 |
+
latest_blocks = []
|
28 |
+
for block_number in range(eth.block_number, eth.block_number-10, -1):
|
29 |
+
block = eth.get_block(block_number)
|
30 |
+
latest_blocks.append(block)
|
31 |
+
|
32 |
+
latest_transactions = []
|
33 |
+
for tx in latest_blocks[-1]['transactions'][-10:]:
|
34 |
+
transaction = eth.get_transaction(tx)
|
35 |
+
latest_transactions.append(transaction)
|
36 |
+
|
37 |
+
current_time = time.time()
|
38 |
+
|
39 |
+
return render_template('index.html',
|
40 |
+
miners=config.MINERS,
|
41 |
+
current_time=current_time,
|
42 |
+
eth=eth,
|
43 |
+
ethereum_price=ethereum_price,
|
44 |
+
latest_blocks=latest_blocks,
|
45 |
+
latest_transactions=latest_transactions)
|
46 |
+
|
47 |
+
@app.route("/address")
|
48 |
+
def address():
|
49 |
+
address = request.args.get('address')
|
50 |
+
|
51 |
+
ethereum_price = get_ethereum_price()
|
52 |
+
|
53 |
+
try:
|
54 |
+
address = w3.toChecksumAddress(address)
|
55 |
+
except:
|
56 |
+
flash('Invalid address', 'danger')
|
57 |
+
return redirect('/')
|
58 |
+
|
59 |
+
balance = w3.eth.get_balance(address)
|
60 |
+
balance = w3.fromWei(balance, 'ether')
|
61 |
+
|
62 |
+
return render_template('address.html', ethereum_price=ethereum_price, address=address, balance=balance)
|
63 |
+
|
64 |
+
@app.route("/block/<block_number>")
|
65 |
+
def block(block_number):
|
66 |
+
block = w3.eth.get_block(int(block_number))
|
67 |
+
|
68 |
+
return render_template('block.html', block=block)
|
69 |
+
|
70 |
+
@app.route('/transaction/<hash>')
|
71 |
+
def transaction(hash):
|
72 |
+
tx = w3.eth.get_transaction(hash)
|
73 |
+
value = w3.fromWei(tx.value, 'ether')
|
74 |
+
receipt = w3.eth.get_transaction_receipt(hash)
|
75 |
+
ethereum_price = get_ethereum_price()
|
76 |
+
|
77 |
+
gas_price = w3.fromWei(tx.gasPrice, 'ether')
|
78 |
+
|
79 |
+
return render_template('transaction.html', tx=tx, value=value, receipt=receipt, gas_price=gas_price, ethereum_price=ethereum_price)
|
80 |
+
|
81 |
+
|
82 |
+
app.run()
|