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

  • SEARCH
  • Home
  • 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 4030748
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:30:40+00:00 2026-05-20T11:30:40+00:00

I’m a beginner in programming and I want to find the easiest way of

  • 0

I’m a beginner in programming and I want to find the easiest way of doing this. I have information which has a line in it that shows when it was updated in UTC time, now i want to write my program to ask if info is within the last 24 hours than print the info. I’m working in Python 3, Thanks

import datetime
import urllib.request
def findEarthquake(entry):
    start= entry.find("<titile>") +7
    end= entry.find("</title>")
    eq= entry[start:end]
    return eq
def findQuakeTime(entry):
    start= entry.find("<p>") +3
    end= entry.find("<br>") -3
    time=entry[start:end]
    return time 
page= urllib.request.urlopen("http://earthquake.usgs.gov/eqcenter/catalogs/7day-M2.5.xml")
text= page.read().decode("utf8")
start= text.find("<entry>") +7
earthquakeList=[]

while start >= 0:
    end= text.find("</entry>", start)
    entry= text[start:end]
    quake= findEarthquake(entry)
    quakeTime= findQuakeTime(entry)
  • 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-05-20T11:30:40+00:00Added an answer on May 20, 2026 at 11:30 am

    Looking at the data being provided by USGS, it seems they already provide this info to you. For example, in the first entry I see <category label="Age" term="Past day"/>, while the last is <category label="Age" term="Past week"/>.

    Assuming you trust this information, you can extract it just as you do the title and time:

    def findQuakeAge(entry):
        start = entry.find('<category label="Age" term="') + 28
        end = entry.find('"/>', start)
        age = entry[start:end]
        return age
    

    Then you can filter your data based on whether the age is "Past day" or not.

    Update: And here’s how to check the dates manually.

    from datetime import datetime, timedelta
    
    quakeTime = datetime.strptime(quakeTime, "%A, %B %d, %Y %H:%M:%S %Z")
    
    if datetime.now() - quakeTime < timedelta(days=1):
        # quake was less than a day ago
    

    Note that strptime() wants the time zone, so you should remove the -3 from your findQuakeTime() code.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I have an array which has BIG numbers and small numbers in it. I
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am doing a simple coin flipping experiment for class that involves flipping a

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.