Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Need help creating a simple script
#1
Ok so im using python idle, version 3.7.8, and im a complete noob literally just started. I want to create a simple script to close/kill and open a application at a given time, not the clock though, just like a kitchen timer. I got all the import stuff down just need help with the closing and opening at certain times? Any help is appreciated...
Quote
#2
Hello buddy,

Share what you have currently, using
 
and we will see what we can add onto it, to hopefully help you accomplish your goal.
Quote
#3
import webbrowser


chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'

webbrowser.get(chrome_path).open('https://www.halowaypoint.com/en-us/news')
I want it to close than open at a given time
Yoriz wrote Jul-13-2020, 08:27 AM:
Please post all code, output and errors (in it's entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.
Quote
#4
Okay, so the easiest option here requiring very little knowledge of python, is to just create an executable. Then you can set it to run everyday at a certain time using windows scheduler. Then to close/exit i would set a delay using the time module with sleep in the script itself. Again, this is the easiest option, in my opinion. You would also need to implement the OS module to close the process.

Example:

os.system("taskkill /im chrome.exe /f")
Quote
#5
I want it in seconds, i have no idea about the "time module" that's why im here. Windows scheduler is not needed here.
Quote
#6
Okay. Well here is an example of the time module.

from time import sleep
import webbrowser
import os

webbrowser.open_new('https://www.halowaypoint.com/en-us/news') # This opens URL with default browser lets assume its chrome.

# Below will wait for 6 minutes before closing chrome.exe 

sleep(600)

os.system("taskkill /im chrome.exe /f")

All this being said. If you want to ensure you don't miss any halo news for example. It wouldn't be too hard to write a script that automatically sends you an email when there is a new post/article with either the link to it or the article itself.

I could probably do this for you.

That all being said, i would really advise you to start learning Python and learn to implement all this stuff yourself, its a really fascinating language with so much to offer, and there are tonnes of communities online like this one here that jump at the opportunity to help you progress.

Harley
Quote
#7
This is what i got:

Traceback (most recent call last):
File "C:\Users\SystemAdmin\Desktop\testpy.py", line 13, in <module>
sleep(30)
NameError: name 'sleep' is not defined


This is what i put down:import webbrowser


chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'

webbrowser.get(chrome_path).open('https://www.halowaypoint.com/en-us/news')


import time


sleep(30)

os.system("taskkill /im chrome.exe /f")

But then i want it to open again, after that time is up.

Im using way point for more of a message grabber. I actually plan on dedicating most of my time on learning all languages. I'm just starting, and this stuff fascinates me. Thanks for the help :D
Quote
#8
A. You need to write your code using the Python tag like i have done, otherwise people frequently don't understand what you've written.

B. Back to your code:

import webbrowser
from time import sleep # put all your imports at the top, its good practice when coding no matter the language. (Also note i did 'from time import sleep' not just 'import time'. You can just use 'import time', then in the code you need to do 'time.sleep(30)'

chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s' # If you want to open the url with your default browser for easiness you can just use the code that i used. 

webbrowser.get(chrome_path).open('https://www.halowaypoint.com/en-us/news') # Checkout webbrowser docs for more info

sleep(30)

os.system("taskkill /im chrome.exe /f") # When this is run it will terminate all processes named 'chrome.exe' 

C. Checkout webbrowser documentation here for some information: https://docs.python.org/3/library/webbrowser.html

D. If you want this to close and re-open in a new browser (Refresh The Page) then you can just wrap the entire code in a while loop. I wouldn't advise this, there are better solutions to your requirement here.

E. What do you mean message grabber?
Quote
#9
I dont know anything about loops either. Like i said i just started. Way point has a messenger, and i need to keep looking at it to communicate with other people, and instead of minimizing it will just pop up, and close on its own. K it worked!!! Ok so how do i do the "while loop"?
Quote
#10
Perhaps you need to work through a book or tutorial on the language, if you don't know basic things like how to use while loops?
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Creating a simple rate limiter. DreamingInsanity 0 302 May-28-2020, 11:08 AM
Last Post: DreamingInsanity
  Creating an executable from a script wolf8963 6 592 May-11-2020, 05:23 PM
Last Post: wolf8963
  Need help creating complex loop around existing script CephloRhod 5 425 Apr-16-2020, 01:23 PM
Last Post: deanhystad
  Simple text to binary python script gmills13 2 429 Feb-04-2020, 08:44 PM
Last Post: snippsat
  Creating a List with many variables in a simple way donnertrud 1 337 Jan-11-2020, 03:00 PM
Last Post: Clunk_Head
  Made a simple script for android (really simple) but it is not running anddontyoucomebacknomore 2 654 Mar-06-2019, 12:19 AM
Last Post: anddontyoucomebacknomore
  Simple script that seems to misbehave? Nwb 1 759 Jun-10-2018, 05:30 AM
Last Post: Nwb
  First time with Python.. need help with simple script shakir_abdul_ahad 7 2,514 May-06-2018, 09:28 AM
Last Post: killerrex
  help with a simple script juanb007 4 1,316 May-01-2018, 08:06 PM
Last Post: ThiefOfTime
  Simple script writted by a dumb dude, myself mm14ag 2 893 Apr-28-2018, 11:48 AM
Last Post: mm14ag

Forum Jump:


Users browsing this thread: 1 Guest(s)