-->

Welcome to our Coding with python Page!!! hier you find various code with PHP, Python, AI, Cyber, etc ... Electricity, Energy, Nuclear Power

Showing posts with label PostgreSQL. Show all posts
Showing posts with label PostgreSQL. Show all posts

Saturday, 29 April 2023

How to Insert Progress Bar Data Using Python Flask, Bootstrap and PostgreSQL

How to Insert Progress Bar Data Using #Python #Flask, #Bootstrap and #PostgreSQL



Here's a general outline of how you can insert progress bar data using Python Flask, Bootstrap, and PostgreSQL:

1. Create a PostgreSQL database with a table to store the progress bar data. The table should have columns for the progress bar ID, the percentage complete, and any other relevant information.

2. In your Flask application, define a route for the page that will display the progress bar. Within this route, you will need to query the database to retrieve the progress bar data and pass it to the HTML template.

3. Create an HTML template that displays the progress bar using Bootstrap's progress bar component. Within the template, you can use Flask's template language to insert the progress bar data into the appropriate HTML elements.

4. Create a JavaScript function that periodically sends an AJAX request to the Flask route you defined earlier to retrieve the latest progress bar data. This function can then update the progress bar displayed on the page accordingly.

5. When the progress bar is complete, use another Flask route to update the database with the final progress bar data.

Here's some sample code to get you started:

  1. Create a PostgreSQL table to store the progress bar data:
sql
CREATE TABLE progress_bars ( id SERIAL PRIMARY KEY, percentage_complete INTEGER, other_info TEXT );
  1. Define a Flask route to retrieve the progress bar data and render the HTML template:
python
@app.route('/progress') def progress(): # Retrieve the progress bar data from the database progress_data = db.execute('SELECT percentage_complete FROM progress_bars WHERE id = 1').fetchone() # Render the HTML template with the progress bar data return render_template('progress.html', progress_data=progress_data)
  1. Create an HTML template to display the progress bar:
html
<div class="progress"> <div class="progress-bar" role="progressbar" style="width: {{ progress_data }}%;" aria-valuenow="{{ progress_data }}" aria-valuemin="0" aria-valuemax="100">{{ progress_data }}%</div> </div>
  1. Create a JavaScript function to periodically update the progress bar:
javascript
function updateProgressBar() { $.ajax({ url: '/progress', success: function(data) { // Update the progress bar with the latest data $('.progress-bar').width(data + '%').attr('aria-valuenow', data).text(data + '%'); // If the progress bar is complete, stop updating if (data >= 100) { clearInterval(progressInterval); } } }); } // Start updating the progress bar every 5 seconds var progressInterval = setInterval(updateProgressBar, 5000);
  1. Create another Flask route to update the progress bar data when it's complete:
python
@app.route('/progress/complete') def progress_complete(): # Update the database with the final progress bar data db.execute('UPDATE progress_bars SET percentage_complete = 100 WHERE id = 1') db.commit() # Return a success message return 'Progress bar complete!'

Note that this is just a basic outline, and you may need to modify the code to fit your specific use case. Additionally, you will need to set up your Flask application to connect to your PostgreSQL database, and include the appropriate Bootstrap and jQuery libraries in your HTML template.

Free postgresql hosting Solutions

Is it possible to host PostgreSQL for free?

Yes, it is possible to find free PostgreSQL hosting options. However, it's important to note that free hosting often comes with limitations in terms of storage space, bandwidth, and features. Additionally, some free hosting services may display ads on your website or may not offer adequate security measures.

Here are a few options for free PostgreSQL hosting:

  1. Heroku: Heroku offers a free tier of its PostgreSQL hosting service, with up to 10,000 rows of data and 20 connections. However, it does have some limitations, such as sleeping apps after 30 minutes of inactivity. (https://www.heroku.com/

  2. ElephantSQL: ElephantSQL offers a free plan with a 20 MB database size limit, limited to one active database at a time. It also has limitations on the number of connections and daily backups. (https://www.elephantsql.com/)

  3. A2 Hosting: A2 Hosting offers a 30-day free trial of its PostgreSQL hosting service, with unlimited databases, disk space, and bandwidth. However, after the trial period, you will need to pay for the service. (https://www.a2hosting.com/)

  4. Google Cloud Platform: Google Cloud Platform offers a free tier that includes a limited amount of usage of its Cloud SQL service, which includes support for PostgreSQL. (https://cloud.google.com/)


These are just a few examples of free PostgreSQL hosting options. It's important to research and compare the features and limitations of each option to determine which one is the best fit for your needs.

Saturday, 31 October 2020

how to create a database from batchfile

this script allow you to Create database and tables from batch file

for this save this content in a text editor 
and save it as .bat file



@echo off

:: This batch allow you to create a database

Title Projet xxxx.

 

Echo Database creation 

Echo starting script ... Please wait...

set /p dbname= "enter the name of the new db:"

createdb -h localhost -p 5432 -U postgres -E UTF-8 -e %dbname%

Echo Database created  ...

 

echo end of the process

xxx

create a postgresql database using a batch file


how to restore postgresql database from a backup file

 in order to restore a postgresql database based on a backup file, use a command line (cmd) and enter the following code:




pg_restore -h localhost -p 5432 -U postgres -d testdatabse -v d:\db.backup


with 

localhost: your host name

5432: the used port for postgresql

testdatabase: the new database in which you want to retore you backup file

d:\db.backup: the database backup file.

don't hesitate to write your feedback or comment


Saturday, 22 June 2019

Homebrew install specific version of formula

Let’s start with the simplest case:

1) Check, whether the version is already installed (but not activated)


When homebrew installs a new formula, it puts it in a versioned directory like /usr/local/Cellar/postgresql/9.3.1. Only symbolic links to this folder are then installed globally. In principle, this makes it pretty easy to switch between two installed versions. (*)

If you have been using homebrew for longer and never removed older versions (using, for example brew cleanup), chances are that some older version of your program may still be around. If you want to simply activate that previous version, brew switch is the easiest way to do this.
Check with brew info postgresql (or brew switch postgresql <TAB>) whether the older version is installed:
$ brew info postgresql
postgresql: stable 9.3.2 (bottled)
http://www.postgresql.org/
Conflicts with: postgres-xc
/usr/local/Cellar/postgresql/9.1.5 (2755 files, 37M)
  Built from source
/usr/local/Cellar/postgresql/9.3.2 (2924 files, 39M) *
  Poured from bottle
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/postgresql.rb
# … and some more
We see that some older version is already installed. We may activate it using brew switch:
$ brew switch postgresql 9.1.5
Cleaning /usr/local/Cellar/postgresql/9.1.5
Cleaning /usr/local/Cellar/postgresql/9.3.2
384 links created for /usr/local/Cellar/postgresql/9.1.5
Let’s double-check what is activated:
$ brew info postgresql
postgresql: stable 9.3.2 (bottled)
http://www.postgresql.org/
Conflicts with: postgres-xc
/usr/local/Cellar/postgresql/9.1.5 (2755 files, 37M) *
  Built from source
/usr/local/Cellar/postgresql/9.3.2 (2924 files, 39M)
  Poured from bottle
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/postgresql.rb
# … and some more
Note that the star * has moved to the newly activated version
(*) Please note that brew switch only works as long as all dependencies of the older version are still around. In some cases, a rebuild of the older version may become necessary. Therefore, using brew switch is mostly useful when one wants to switch between two versions not too far apart.

2) Check, whether the version is available as a tap


Especially for larger software projects, it is very probably that there is a high enough demand for several (potentially API incompatible) major versions of a certain piece of software. As of March 2012, Homebrew 0.9 provides a mechanism for this: brew tap & the homebrew versions repository.
That versions repository may include backports of older versions for several formulae. (Mostly only the large and famous ones, but of course they’ll also have several formulae for postgresql.)
brew search postgresql will show you where to look:
$ brew search postgresql
postgresql
homebrew/versions/postgresql8    homebrew/versions/postgresql91
homebrew/versions/postgresql9    homebrew/versions/postgresql92
We can simply install it by typing
$ brew install homebrew/versions/postgresql8
Cloning into '/usr/local/Library/Taps/homebrew-versions'...
remote: Counting objects: 1563, done.
remote: Compressing objects: 100% (943/943), done.
remote: Total 1563 (delta 864), reused 1272 (delta 620)
Receiving objects: 100% (1563/1563), 422.83 KiB | 339.00 KiB/s, done.
Resolving deltas: 100% (864/864), done.
Checking connectivity... done.
Tapped 125 formula
==> Downloading http://ftp.postgresql.org/pub/source/v8.4.19/postgresql-8.4.19.tar.bz2
# …
Note that this has automatically tapped the homebrew/versions tap. (Check with brew tap, remove with brew untap homebrew/versions.) The following would have been equivalent:
$ brew tap homebrew/versions
$ brew install postgresql8
As long as the backported version formulae stay up-to-date, this approach is probably the best way to deal with older software.

3) Try some formula from the past


The following approaches are listed mostly for completeness. Both try to resurrect some undead formula from the brew repository. Due to changed dependencies, API changes in the formula spec or simply a change in the download URL, things may or may not work.
Since the whole formula directory is a git repository, one can install specific versions using plain git commands. However, we need to find a way to get to a commit where the old version was available.
a) historic times
Between August 2011 and October 2014, homebrew had a brew versions command, which spat out all available versions with their respective SHA hashes. As of October 2014, you have to do a brew tap homebrew/boneyard before you can use it. As the name of the tap suggests, you should probably only do this as a last resort.
E.g.

$ brew versions postgresql
Warning: brew-versions is unsupported and may be removed soon.
Please use the homebrew-versions tap instead:
  https://github.com/Homebrew/homebrew-versions
9.3.2    git checkout 3c86d2b Library/Formula/postgresql.rb
9.3.1    git checkout a267a3e Library/Formula/postgresql.rb
9.3.0    git checkout ae59e09 Library/Formula/postgresql.rb
9.2.4    git checkout e3ac215 Library/Formula/postgresql.rb
9.2.3    git checkout c80b37c Library/Formula/postgresql.rb
9.2.2    git checkout 9076baa Library/Formula/postgresql.rb
9.2.1    git checkout 5825f62 Library/Formula/postgresql.rb
9.2.0    git checkout 2f6cbc6 Library/Formula/postgresql.rb
9.1.5    git checkout 6b8d25f Library/Formula/postgresql.rb
9.1.4    git checkout c40c7bf Library/Formula/postgresql.rb
9.1.3    git checkout 05c7954 Library/Formula/postgresql.rb
9.1.2    git checkout dfcc838 Library/Formula/postgresql.rb
9.1.1    git checkout 4ef8fb0 Library/Formula/postgresql.rb
9.0.4    git checkout 2accac4 Library/Formula/postgresql.rb
9.0.3    git checkout b782d9d Library/Formula/postgresql.rb
As you can see, it advises against using it. Homebrew spits out all versions it can find with its internal heuristic and shows you a way to retrieve the old formulae. Let’s try it.
# First, go to the homebrew base directory
$ cd $( brew --prefix )
# Checkout some old formula
$ git checkout 6b8d25f Library/Formula/postgresql.rb
$ brew install postgresql
# … installing
Now that the older postgresql version is installed, we can re-install the latest formula in order to keep our repository clean:
$ git checkout -- Library/Formula/postgresql.rb
brew switch is your friend to change between the old and the new.
b) prehistoric times
For special needs, we may also try our own digging through the homebrew repo.
$ cd Library/Taps/homebrew/homebrew-core && git log -S'8.4.4' -- Formula/postgresql.rb
git log -S looks for all commits in which the string '8.4.4' was either added or removed in the file Library/Taps/homebrew/homebrew-core/Formula/postgresql.rb. We get two commits as a result.
commit 7dc7ccef9e1ab7d2fc351d7935c96a0e0b031552
Author: Aku Kotkavuo
Date:   Sun Sep 19 18:03:41 2010 +0300

    Update PostgreSQL to 9.0.0.

    Signed-off-by: Adam Vandenberg

commit fa992c6a82eebdc4cc36a0c0d2837f4c02f3f422
Author: David Höppner
Date:   Sun May 16 12:35:18 2010 +0200

    postgresql: update version to 8.4.4
Obviously, fa992c6a82eebdc4cc36a0c0d2837f4c02f3f422 is the commit we’re interested in. As this commit is pretty old, we’ll try to downgrade the complete homebrew installation (that way, the formula API is more or less guaranteed to be valid):
$ git checkout -b postgresql-8.4.4 fa992c6a82eebdc4cc36a0c0d2837f4c02f3f422
$ brew install postgresql
$ git checkout master
$ git branch -d postgresql-8.4.4
You may skip the last command to keep the reference in your git repository.
One note: When checking out the older commit, you temporarily downgrade your homebrew installation. So, you should be careful as some commands in homebrew might be different to the most recent version.

4) Manually write a formula

It’s not too hard and you may then upload it to your own repository. Used to be Homebrew-Versions, but that is now discontinued.

A.) Bonus: Pinning

If you want to keep a certain version of, say postgresql, around and stop it from being updated when you do the natural brew update; brew upgrade procedure, you can pin a formula:
$ brew pin postgresql
Pinned formulae are listed in /usr/local/Library/PinnedKegs/ and once you want to bring in the latest changes and updates, you can unpin it again:
$ brew unpin postgresql

Rank

seo