Advertisement
LorenKPetrov

Python Omegle Online checker

Jan 7th, 2014
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.50 KB | None | 0 0
  1. # Omegle Online
  2. # Saves the number of users on omegle every hour.
  3. # Coded by LKP
  4. # Respect to Don J
  5.  
  6. import os
  7. import ast
  8. import sqlite3
  9. import requests
  10. import urllib2
  11. import time
  12. from datetime import date
  13.  
  14. class omegle(object):
  15.    
  16.     website = "http://omegle.com/status"
  17.     omg_time = time.strftime("%H:%M")
  18.     omg_date = [date.today().day,date.today().month,date.today().year]
  19.    
  20.     def interface(self):
  21.        
  22.         # Basic Interface for a user to use, it works off of numbers so type in the relevant number.
  23.        
  24.         os.system("cls")
  25.         print "\n Welcome to Omegle User Counter!\n Would you like to do?\n 1) Start\n 2) Setup\n 3) Exit"
  26.         choice = raw_input(" > ")
  27.        
  28.         if choice == "1":
  29.             os.system("cls")
  30.             print "\n Starting now!"
  31.             self.start()
  32.         elif choice == "2":
  33.             os.system("cls")
  34.             print "\n Starting setup now!"
  35.             omegle.setup()
  36.         elif choice == "3":
  37.             os.system("cls")
  38.             print "\n Exiting now!"
  39.         else:
  40.             os.system("cls")
  41.             print "\n Unrecognised command!"
  42.             time.sleep(2)
  43.             omegle.interface()
  44.    
  45.     def start(self):
  46.        
  47.         os.system("cls")
  48.         print "\n Grabbing users online now from",self.website
  49.         statusurl = urllib2.urlopen("http://www.omegle.com/status") # Code thanks to Don J
  50.         statustext = statusurl.read() # Code thanks to Don J
  51.         status = ast.literal_eval(statustext)  # Code thanks to Don J
  52.         count = status["count"]  # Code thanks to Don J
  53.         print "\n Saving to database now!"
  54.         connect = sqlite3.connect('Omegle.db')
  55.         omegle = connect.cursor()
  56.         omegle.execute("INSERT INTO user_count VALUES (?, ?, ?)",(count, str(self.omg_date[0])+"-"+str(self.omg_date[1])+"-"+str(self.omg_date[2]), str(self.omg_time)))
  57.         connect.commit()
  58.         os.system("cls")
  59.         print "\n Waiting one hour!"
  60.         time.sleep(3600)
  61.         self.start()
  62.    
  63.     def setup(self):
  64.        
  65.         # Checks if the database exists, I could have used Try but they don't really make much difference.
  66.         # Creates the Database to write the online users to.
  67.        
  68.         if os.path.exists("Omegle.db") == True:
  69.             os.system("cls")
  70.             print "\n The database already exists!\n Returning to interface!"
  71.             time.sleep(2)
  72.             self.interface()
  73.         else:
  74.             os.system("cls")
  75.             print "\n Creating the database!"
  76.             connect = sqlite3.connect('Omegle.db')
  77.             omegle = connect.cursor()
  78.             print "\n Creating the table for the users and time!"
  79.             omegle.execute("""CREATE TABLE user_count(users,date,time)""")
  80.             print "\n Database Creation complete!\n returning to interface!"
  81.             time.sleep(2)
  82.             self.interface()
  83.            
  84. omegle = omegle()
  85. omegle.interface()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement