₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,328,963 members, 8,438,153 topics. Date: Friday, 03 July 2026 at 03:32 AM

Toggle theme

Pls I Need Your Assistance �� - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingPls I Need Your Assistance �� (330 Views)

1 Reply (Go Down)

Pls I Need Your Assistance �� by Martinz09(op): 10:00pm On Dec 03, 2024
Good evening everyone,I was given a python project and I have been struggling to complete the task,the task states that;
Create an application that allows a user to enter a currency pairs and then display it in a live chart movement, which should be gotten from an online resource, and then the inputs or the currency pairs the user has entered to check should be saved to a database and displayed when they see their previous history using python.
Pls help me in any little way,I have used web scraping or crawling,it is not giving me the expected results pls help
Re: Pls I Need Your Assistance �� by MindHacker9009(m): 10:18pm On Dec 03, 2024
By ChatGPT your best friend.

To create an application that displays live currency pair movements, saves user input to a database, and displays the history, we can divide the process into these steps:

Frontend User Interface: Use a Python GUI library like tkinter or a web framework like Flask for the user interface.
Fetching Live Data: Use an API, such as Exchange Rates API or similar services, to fetch live currency pair data.
Database Setup: Use SQLite for simplicity (or any database of your choice) to store and retrieve user input history.
Live Charting: Use a library like matplotlib for plotting or plotly for dynamic web-based charts.
Here's the implementation:

Step 1: Install Necessary Libraries
Before you begin, make sure you have these libraries installed:
pip install requests matplotlib flask sqlite3 plotly


Step 2: Code Implementation
1. Backend (API and Database)

import sqlite3
from flask import Flask, request, jsonify
import requests

app = Flask(__name__)
DATABASE = 'currency_pairs.db'

# Initialize Database
def init_db():
conn = sqlite3.connect(DATABASE)
cursor = conn.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS currency_history (
id INTEGER PRIMARY KEY AUTOINCREMENT,
currency_pair TEXT NOT NULL,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
)
"""wink
conn.commit()
conn.close()

@app.route('/add_currency_pair', methods=['POST'])
def add_currency_pair():
data = request.json
currency_pair = data['currency_pair']

conn = sqlite3.connect(DATABASE)
cursor = conn.cursor()
cursor.execute("INSERT INTO currency_history (currency_pair) VALUES (?)", (currency_pair,))
conn.commit()
conn.close()

return jsonify({'message': 'Currency pair added successfully!'})

@app.route('/get_history', methods=['GET'])
def get_history():
conn = sqlite3.connect(DATABASE)
cursor = conn.cursor()
cursor.execute("SELECT currency_pair, timestamp FROM currency_history ORDER BY timestamp DESC"wink
rows = cursor.fetchall()
conn.close()
return jsonify(rows)

@app.route('/get_live_rate', methods=['GET'])
def get_live_rate():
base = request.args.get('base', 'USD')
target = request.args.get('target', 'EUR')
response = requests.get(f"https://api.exchangerate.host/latest?base={base}&symbols={target}"wink
return response.json()

if __name__ == "__main__":
init_db()
app.run(debug=True)


2. Frontend (Python GUI Example using Tkinter)

import tkinter as tk
from tkinter import ttk
import requests
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import time

# Base URL for Flask API
API_BASE = 'http://127.0.0.1:5000'

# Function to fetch live rates
def fetch_live_rate(base, target):
response = requests.get(f"{API_BASE}/get_live_rate", params={"base": base, "target": target})
data = response.json()
return data["rates"][target]

# Function to update database
def save_currency_pair(base, target):
requests.post(f"{API_BASE}/add_currency_pair", json={"currency_pair": f"{base}/{target}"})

# Live Chart Setup
fig, ax = plt.subplots()
times, rates = [], []

def update_chart(base, target):
def fetch_and_update(frame):
rate = fetch_live_rate(base, target)
times.append(time.strftime('%H:%M:%S'))
rates.append(rate)

ax.clear()
ax.plot(times[-20:], rates[-20:])
ax.set_title(f"Live Rate: {base}/{target}"wink
ax.set_xlabel("Time"wink
ax.set_ylabel("Exchange Rate"wink

ani = FuncAnimation(fig, fetch_and_update, interval=1000)
plt.show()

# Main GUI
def main():
root = tk.Tk()
root.title("Currency Pair Tracker"wink

ttk.Label(root, text="Base Currency"wink.grid(row=0, column=0, padx=10, pady=10)
base_currency = ttk.Entry(root)
base_currency.grid(row=0, column=1, padx=10, pady=10)

ttk.Label(root, text="Target Currency"wink.grid(row=1, column=0, padx=10, pady=10)
target_currency = ttk.Entry(root)
target_currency.grid(row=1, column=1, padx=10, pady=10)

def track_currency():
base = base_currency.get()
target = target_currency.get()
save_currency_pair(base, target)
update_chart(base, target)

ttk.Button(root, text="Track Live", command=track_currency).grid(row=2, column=0, columnspan=2, pady=20)

def show_history():
response = requests.get(f"{API_BASE}/get_history"wink
history = response.json()
for row in history:
print(f"Currency Pair: {row[0]}, Timestamp: {row[1]}"wink

ttk.Button(root, text="Show History", command=show_history).grid(row=3, column=0, columnspan=2, pady=10)

root.mainloop()

if __name__ == "__main__":
main()


How it Works
Run the Backend: Start the Flask API backend first.
Run the Frontend: Launch the Tkinter app to input currency pairs.
Track Live Data: Use matplotlib to plot live exchange rates.
Save and View History: Save the selected currency pairs to a database and retrieve them later.
Re: Pls I Need Your Assistance �� by Martinz09(op): 10:21pm On Dec 03, 2024
MindHacker9009:
By ChatGPT your best friend.

To create an application that displays live currency pair movements, saves user input to a database, and displays the history, we can divide the process into these steps:

Frontend User Interface: Use a Python GUI library like tkinter or a web framework like Flask for the user interface.
Fetching Live Data: Use an API, such as Exchange Rates API or similar services, to fetch live currency pair data.
Database Setup: Use SQLite for simplicity (or any database of your choice) to store and retrieve user input history.
Live Charting: Use a library like matplotlib for plotting or plotly for dynamic web-based charts.
Here's the implementation:

Step 1: Install Necessary Libraries
Before you begin, make sure you have these libraries installed:
pip install requests matplotlib flask sqlite3 plotly


Step 2: Code Implementation
1. Backend (API and Database)

import sqlite3
from flask import Flask, request, jsonify
import requests

app = Flask(__name__)
DATABASE = 'currency_pairs.db'

# Initialize Database
def init_db():
conn = sqlite3.connect(DATABASE)
cursor = conn.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS currency_history (
id INTEGER PRIMARY KEY AUTOINCREMENT,
currency_pair TEXT NOT NULL,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
)
"""wink
conn.commit()
conn.close()

@app.route('/add_currency_pair', methods=['POST'])
def add_currency_pair():
data = request.json
currency_pair = data['currency_pair']

conn = sqlite3.connect(DATABASE)
cursor = conn.cursor()
cursor.execute("INSERT INTO currency_history (currency_pair) VALUES (?)", (currency_pair,))
conn.commit()
conn.close()

return jsonify({'message': 'Currency pair added successfully!'})

@app.route('/get_history', methods=['GET'])
def get_history():
conn = sqlite3.connect(DATABASE)
cursor = conn.cursor()
cursor.execute("SELECT currency_pair, timestamp FROM currency_history ORDER BY timestamp DESC"wink
rows = cursor.fetchall()
conn.close()
return jsonify(rows)

@app.route('/get_live_rate', methods=['GET'])
def get_live_rate():
base = request.args.get('base', 'USD')
target = request.args.get('target', 'EUR')
response = requests.get(f"https://api.exchangerate.host/latest?base={base}&symbols={target}"wink
return response.json()

if __name__ == "__main__":
init_db()
app.run(debug=True)


2. Frontend (Python GUI Example using Tkinter)

import tkinter as tk
from tkinter import ttk
import requests
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import time

# Base URL for Flask API
API_BASE = 'http://127.0.0.1:5000'

# Function to fetch live rates
def fetch_live_rate(base, target):
response = requests.get(f"{API_BASE}/get_live_rate", params={"base": base, "target": target})
data = response.json()
return data["rates"][target]

# Function to update database
def save_currency_pair(base, target):
requests.post(f"{API_BASE}/add_currency_pair", json={"currency_pair": f"{base}/{target}"})

# Live Chart Setup
fig, ax = plt.subplots()
times, rates = [], []

def update_chart(base, target):
def fetch_and_update(frame):
rate = fetch_live_rate(base, target)
times.append(time.strftime('%H:%M:%S'))
rates.append(rate)

ax.clear()
ax.plot(times[-20:], rates[-20:])
ax.set_title(f"Live Rate: {base}/{target}"wink
ax.set_xlabel("Time"wink
ax.set_ylabel("Exchange Rate"wink

ani = FuncAnimation(fig, fetch_and_update, interval=1000)
plt.show()

# Main GUI
def main():
root = tk.Tk()
root.title("Currency Pair Tracker"wink

ttk.Label(root, text="Base Currency"wink.grid(row=0, column=0, padx=10, pady=10)
base_currency = ttk.Entry(root)
base_currency.grid(row=0, column=1, padx=10, pady=10)

ttk.Label(root, text="Target Currency"wink.grid(row=1, column=0, padx=10, pady=10)
target_currency = ttk.Entry(root)
target_currency.grid(row=1, column=1, padx=10, pady=10)

def track_currency():
base = base_currency.get()
target = target_currency.get()
save_currency_pair(base, target)
update_chart(base, target)

ttk.Button(root, text="Track Live", command=track_currency).grid(row=2, column=0, columnspan=2, pady=20)

def show_history():
response = requests.get(f"{API_BASE}/get_history"wink
history = response.json()
for row in history:
print(f"Currency Pair: {row[0]}, Timestamp: {row[1]}"wink

ttk.Button(root, text="Show History", command=show_history).grid(row=3, column=0, columnspan=2, pady=10)

root.mainloop()

if __name__ == "__main__":
main()


How it Works
Run the Backend: Start the Flask API backend first.
Run the Frontend: Launch the Tkinter app to input currency pairs.
Track Live Data: Use matplotlib to plot live exchange rates.
Save and View History: Save the selected currency pairs to a database and retrieve them Thanks sir
Re: Pls I Need Your Assistance �� by Martinz09(op): 10:22pm On Dec 03, 2024
[quote author=Martinz09 post=133150489][/quote]Thank you sir
Re: Pls I Need Your Assistance �� by Martinz09(op): 10:22pm On Dec 03, 2024
[quote author=Martinz09 post=133150489][/quote]Thank you sir
Re: Pls I Need Your Assistance �� by MindHacker9009(m): 10:34pm On Dec 03, 2024
Martinz09:
Thank you sir
No problem. If you need further customization, just give ChatGPT a shout at: https://chatgpt.com
Re: Pls I Need Your Assistance �� by Martinz09(op): 10:37pm On Dec 03, 2024
MindHacker9009:
No problem. If you need further customization, just give ChatGPT a shout at: https://chatgpt.com
Okay.Thank you
Re: Pls I Need Your Assistance �� by MindHacker9009(m): 11:20am On Dec 04, 2024
Martinz09:
Okay.Thank you
No worries. Happy coding.
1 Reply

Pls I Need Ur Advice On My CareerIs The Macbook Worth It? Pls I Need Validations.Pls I Need C# Tutorials Pls Someone Help Me234

Meet Silq- The First High-level Programming Language For Quantum ComputersCan This App Help Solve Police Brutality, Domestic/sexual Violence In Nigeria?Magento Upgrade Services, Upgrade Magento Version - Magento India