Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7861045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:32:31+00:00 2026-06-02T22:32:31+00:00

I have a python script that gets data from a USB weather station, now

  • 0

I have a python script that gets data from a USB weather station, now it puts the data into MySQL whenever the data is received from the station.

I have a MySQL class with an insert function, what i want i that the function checks if it has been run the last 5 minutes if it has, quit.

Could not find any code on the internet that does this.

Maybe I need to have a sub-process, but I am not familiar with that at all.

Does anyone have an example that I can use?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T22:32:32+00:00Added an answer on June 2, 2026 at 10:32 pm

    Probably the most straight-forward approach (you can put this into a decorator if you like, but that’s just cosmetics I think):

    import time
    import datetime
    
    class MySQLWrapper:
      def __init__(self, min_period_seconds):
        self.min_period = datetime.timedelta(seconds=min_period_seconds)
        self.last_calltime = datetime.datetime.now() - self.min_period
      def insert(self, item):
        now = datetime.datetime.now()
        if now-self.last_calltime < self.min_period:
          print "not insert"
        else:
         self.last_calltime = now
         print "insert", item
    
    m = MySQLWrapper(5)
    m.insert(1) # insert 1
    m.insert(2) # not insert
    time.sleep(5)
    m.insert(3) # insert 3
    

    As a side-note: Have you noticed RRDTool during your web-search for related stuff? It does apparantly what you want to achieve, i.e.

    • a database to store the most recent values of arbitrary resolution/update frequency.
    • extrapolation/interpolation of values if updates are too frequent or missing.
    • generates graphs from the data.

    An approach could be to store all data you can get into your MySQL database and forward a subset to such RRDTool database to generate a nice time series visualization of it. Depending on what you might need.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Python script that for-loops through some objects and fetches data from
I have a python script that is constantly grabbing data from Twitter and writing
I have written a script that gets data from solr for which date is
I have a python script that retrieves information from a web service and then
I have a Python script that queries a MySQL database every 5 seconds, gathering
Basically I have a script in Python that takes several letters, gets every combination
I want to make a really script in Python that gets the contents from
I have python script that converts data.xml to html using stylesheet.xsl. And i have
I have a Python script that uses built-in modules but also imports a number
I have a python script that uses threads and makes lots of HTTP requests.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.