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 7753745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:07:47+00:00 2026-06-01T12:07:47+00:00

i been trying to code an IRC bot, while i have succeed. I am

  • 0

i been trying to code an IRC bot, while i have succeed. I am having problems implementing something i want to do. the code works fine, but i have issues in the following:

since the bot uses a While loop to read commands from the IRC when i add a second While with a time.sleep(seconds) the bot does not connect because it reads my second loop and pauses the connection not in time to response the :PING do it disconnects. i been searching but the mor ei search the more confused i get because i don’t know what should i try.

stackless, multithreads, subprocess. there are so many results that i just get more confused. so what would be the best method i am trying an RSS bot the bot works fine if i use the command !rss in the IRC channel but i need it to check for new ones ever 10 minutes and if use a sleep command the main loop messes up.

here is my code:

#!/usr/bin/python

import socket, sys, string, time, feedparser, hashlib
port = 6667
nick = "RSSbot"
host = 'irc.server.com'
name =  "RSSBOT"
channel = '#debug'
ident = 'rssbot'
irc = socket.socket()
irc.connect ( (host, port) )
irc.send ( 'NICK ' + nick + '\r\n' )
irc.send ( 'USER ' + ident + ' ' +  ident + ' ' + ident + ' :rssbot\r\n' )

def readRss():
    feedurl = feedparser.parse("http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=username")
    newest = feedurl['items'][0].title
    newest = newest.replace("username:","")
    msg = newest.split("http://")
    title = msg[0]
    url = msg[1]
    url = "http://" + url
    e = feedurl.entries[2]
    threadurl = e.link
    id = hashlib.md5(url + title).hexdigest()
    irc.send ("PRIVMSG #debug :Tittle:%s\r\n" % newest)
    irc.send ("PRIVMSG #debug :URL: %s\r\n" % url)
    irc.send ("PRIVMSG #debug :MD5: %s\r\n" % id)
while 1:
    data = irc.recv ( 1024 )
    print(data)

    if data.find ( '376' ) != -1:
        irc.send( 'JOIN ' + channel + '\r\n' )
    if data.find ( 'PING' ) != -1:
        irc.send( 'PONG ' + data.split() [1] + '\r\n')
    if data.find ( '!rss' ) != -1:
        feedurl = feedparser.parse("http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=username")
        newest = feedurl['items'][0].title
        newest = newest.replace("username:","")
        msg = newest.split("http://")
        title = msg[0]
        url = msg[1]
        url = "http://" + url
        #e = feedurl.entries[2]
        #threadurl = e.link
        id = hashlib.md5(url + title).hexdigest()
        irc.send ("PRIVMSG #debug :Tittle:%s\r\n" % newest)
        irc.send ("PRIVMSG #debug :URL: %s\r\n" % url)
        irc.send ("PRIVMSG #debug :MD5: %s\r\n" % id)
    while true:
        readRss()
        time.sleep(300)

if i add a while :true inside the while 1: with a time.sleep(300) the sleep command conflicts with the while 1: loop which i need to do something similar so i could check for new feeds every x minutes. what could i do?

  • 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-01T12:07:48+00:00Added an answer on June 1, 2026 at 12:07 pm

    Instead of a new loop, use a separate timer.

    import time
    last_update = time.time()
    
    while 1:
       # the rest of your while loop as usual
       now = time.time()
       if now - last_update > 300:
           # you've waited 300 seconds
           # check feeds or whatever 
           last_update = now
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been figuring about and trying to make my IRC bot send private
I have been trying to code this for a while but I am so
I have been trying to find a code snippet to do an unsharp mask
I've been trying to implement unit testing and currently have some code that does
I have been trying to code merge sort, without creating additional arrays for keeping
I've been trying to code this page for a while, but my biggest problem
I have been trying to optimize some code which handles raw pixel data. Currently
I have been trying to write some code that asks the user for several
I have been trying to work on a simple code for two days now.
I have been trying to adapt my code (a webservice) to get the SQLServerMessages:

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.