Commit d52e6925 authored by DAAndryukin's avatar DAAndryukin
Browse files

Update PRAKTIKA2.txt

parent ff3cf8d7
import pika
import json
import matplotlib.pyplot as plt
latitude = []
longtitude = []
coordinates = {
'latitude': 0,
'longtitude': 0,
}
credentials = pika.PlainCredentials('user1', '123456')
parameters = pika.ConnectionParameters('217.9.89.211', 5672, 'vh2', credentials)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
channel.queue_declare(queue = 'queue1')
fig = plt.figure()
ax = plt.subplots()
plt.ion()
def graph(lat, long):
plt.grid(True)
plt.xlim(-35.36400, -35.36200)
plt.ylim(149.16500, 149.16700)
plt.title('Graph')
plt.xlabel('Latitude')
plt.ylabel('Longtitude')
latitude.append(lat)
longtitude.append(long)
plt.plot(latitude, longtitude)
plt.draw()
plt.gcf().canvas.flush_events()
def callback(ch, method, properties, body):
coordinates_current = json.loads(body)
coordinates['latitude'] = coordinates_current['current_latitude']
coordinates['longtitude'] = coordinates_current['current_longtitude']
print(coordinates)
graph(coordinates['latitude'], coordinates['longtitude'])
channel.basic_consume(queue='queue1', on_message_callback = callback, auto_ack=True)
print(' [*] Waiting for messages. To exit press CTRL+C')
plt.show()
channel.start_consuming()
connection.close()
plt.ioff()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment