When running the Function with no names on the input lists, it gives everyone the approtriate time based on the varible listed. If we have the input varibale have a name it gives everyone time off instead of just that indivudual.
There are some lists associated with this as well and that part works fine.
this is the required resources:
from openpyxl import Workbook
from datetime import timedelta, datetime
import random
def add_agents_w1():
num = 4
c = ["B","C","D","E","F"]
tow1 = input("IF anyone taking time off enter 1st
person now: \n")
tow12 = input("If someone else is taking time off enter
2nd person now: \n")
for x in tl:
ws1[f"A{num}"] = x
ws1[f"I{num}"] = x
for f in c:
if x in tow1 or tow12:
ws1[f'{f}{num}'] = "OFF"
else:
ws1[f"{f}{num}"] = s2t
num += 1
wb.save(dest_filename)
Related
I am trying to use pystray to create a icon on tasktray, it is working on windows but now I am building one for Mac. I need the program minimize to tasktray on run on background. so I need to use icon.run_detached() instead of icon.run().
However, it keep crashing the app and I read the documents seems that I need to give some darwin_nsapplication = AppKit.NSApplication.sharedApplication() to the code but I really don't know how to implement this. here is my code.
import tkinter as tk
import time
import pystray
from tkinter import *
from tkinter import messagebox
from PIL import Image
import AppKit
`class Gui():
def __init__(self):
self.window = tk.Tk()
self.darwin_nsapplication = AppKit.NSApplication.sharedApplication()
self.image = Image.open("./images/noname.png")
self.menu = (
pystray.MenuItem('Show', self.show_window),
pystray.MenuItem('Quit', self.quit_window)
)
# Declaration of variables
self.hour=StringVar()
self.minute=StringVar()
self.second=StringVar()
# setting the default value as 0
self.hour.set("00")
self.minute.set("00")
self.second.set("00")
# Use of Entry class to take input from the user
hourEntry= Entry(self.window, width=3, font=("Arial",18,""),
textvariable=self.hour)
hourEntry.place(x=80,y=20)
minuteEntry= Entry(self.window, width=3, font=("Arial",18,""),
textvariable=self.minute)
minuteEntry.place(x=130,y=20)
secondEntry= Entry(self.window, width=3, font=("Arial",18,""),
textvariable=self.second)
secondEntry.place(x=180,y=20)
# button widget
btn = Button(self.window, text='Set Time Countdown', bd='5',
command= self.submit)
btn.place(x = 70,y = 120)
def submit(self):
try:
# the input provided by the user is
# stored in here :temp
temp = int(self.hour.get())*3600 + int(self.minute.get())*60 + int(self.second.get())
except:
print("Please input the right value")
while temp >-1:
# divmod(firstvalue = temp//60, secondvalue = temp%60)
mins,secs = divmod(temp,60)
# Converting the input entered in mins or secs to hours,
# mins ,secs(input = 110 min --> 120*60 = 6600 => 1hr :
# 50min: 0sec)
hours=0
if mins >60:
# divmod(firstvalue = temp//60, secondvalue
# = temp%60)
hours, mins = divmod(mins, 60)
# using format () method to store the value up to
# two decimal places
self.hour.set("{0:2d}".format(hours))
self.minute.set("{0:2d}".format(mins))
self.second.set("{0:2d}".format(secs))
# updating the GUI window after decrementing the
# temp value every time
self.window.update()
time.sleep(1)
# when temp value = 0; then a messagebox pop's up
# with a message:"Time's up"
if (temp == 0):
messagebox.showinfo("Time Countdown", "Time's up ")
# after every one sec the value of temp will be decremented
# by one
temp -= 1
def quit_window(self):
self.icon.stop()
self.window.destroy()
def show_window(self):
self.icon.stop()
self.window.protocol('WM_DELETE_WINDOW', self.withdraw_window)
self.window.after(0, self.window.deiconify)
def withdraw_window(self):
self.window.withdraw()
self.icon = pystray.Icon("name", self.image, "title", self.menu)
self.icon.run_detached()
if __name__ in '__main__':
app = Gui()
app.window.protocol('WM_DELETE_WINDOW', app.withdraw_window)
app.window.mainloop()`
I tried to add darwin_nsapplication to icon like self.icon = pystray.Icon("name", self.image, "title", self.menu,self.darwin_nsapplication)
But it is said 6 arguments are given, 2-5 are needed.
I'm a newbie of programming, and i have a basic question.
The bottom is the code I made to extract Excel data.
import os
path = "./data"
file_list = os.listdir(path)
from openpyxl import load_workbook
results = []
for file_name_raw in file_list:
file_name = "./data/"+file_name_raw
wb = load_workbook(filename=file_name, data_only=True)
Ad = wb.get_sheet_by_name('Advanced')
result = []
**result.append(Ad['C1'].value)
result.append(Ad['C2'].value)
result.append(Ad['C3'].value)
result.append(Ad['C4'].value)
result.append(Ad['C5'].value)
...
result.append(Ad['C100'].value)**
results.append(result)
print(results)
If i want to repeat the number in the result.append(Ad['C number ].value)
how can i make a code? Is there a way to use for loop?
You can write this in a for loop.
Define a range for your repetitions, let's say you want to do result.append(...) for 100 times, then:
Assuming you are using python
for i in range(1, 100):
result.append(Ad['C' + str(i) ].value)
OR
By specifying a limit:
n = 100
for i in range(1, n):
result.append(Ad['C' + str(i) ].value)
The hackerrank challenge is in the following url: https://www.hackerrank.com/challenges/python-time-delta/problem
I got testcase 0 correct, but the website is saying that I have wrong answers for testcase 1 and 2, but in my pycharm, I copied the website expected output and compared with my output and they were exactly the same.
Please have a look at my code.
#!/bin/pyth
# Complete the time_delta function below.
from datetime import datetime
def time_delta(tmp1, tmp2):
dicto = {'Jan':1, 'Feb':2, 'Mar':3,
'Apr':4, 'May':5, 'Jun':6,
'Jul':7, 'Aug':8, 'Sep':9,
'Oct':10, 'Nov':11, 'Dec':12}
# extracting t1 from first timestamp without -xxxx
t1 = datetime(int(tmp1[2]), dicto[tmp1[1]], int(tmp1[0]), int(tmp1[3][:2]),int(tmp1[3][3:5]), int(tmp1[3][6:]))
# extracting t1 from second timestamp without -xxxx
t2 = datetime(int(tmp2[2]), dicto[tmp2[1]], int(tmp2[0]), int(tmp2[3][:2]), int(tmp2[3][3:5]), int(tmp2[3][6:]))
# converting -xxxx of timestamp 1
t1_utc = int(tmp1[4][:3])*3600 + int(tmp1[4][3:])*60
# converting -xxxx of timestamp 2
t2_utc = int(tmp2[4][:3])*3600 + int(tmp2[4][3:])*60
# absolute difference
return abs(int((t1-t2).total_seconds()-(t1_utc-t2_utc)))
if __name__ == '__main__':
# fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
for t_itr in range(t):
tmp1 = list(input().split(' '))[1:]
tmp2 = list(input().split(' '))[1:]
delta = time_delta(tmp1, tmp2)
print(delta)
t1_utc = int(tmp1[4][:3])*3600 + int(tmp1[4][3:])*60
For a time zone like +0715, you correctly add “7 hours of seconds” and “15 minutes of seconds”
For a timezone like -0715, you are adding “-7 hours of seconds” and “+15 minutes of seconds”, resulting in -6h45m, instead of -7h15m.
You need to either use the same “sign” for both parts, or apply the sign afterwards.
I work actually on my raspberry 3 without internet for my internship.
Firstly I created a python script that I schedule with Cron to update my raspberry's hour every 12h.
Secondly, I have another script should run continually.
But I observed that, when I update the time, my script that run continually, doesn't update its datetime.
So I would like to reboot it, to allow the script to take the time in consideration.
here my script I would like to reboot.
from math import *
import pyorbital
from pyorbital import tlefile
from pyorbital.orbital import Orbital
import serial
import time
from datetime import datetime
import os
import sat_class
import predict
import rotator_treshold_test
def rotator_set (azel,v):
if v == False:
az = 0
el = 90
print(('waiting \n azimuth = %f elevation = %f\n\n')%(az,el))
else:
az = azel[0]
if azel[1] < 0:
el = 0
else :
el = azel[1]
print(('tracking satellite \n azimuth = %f elevation = %f\n\n')%(az,el))
def satellite_track():
k=0
saved = [0]
p = '?'
b = '?'
sat = sat_class.Satellite()
mission = predict.Mission()
verif = mission.verif
if verif == False:
mission = predict.Mission()
now= mission.now
print(now)
azel = [0,0] # we don't need to put azel here we are in waiting mode .
rotator_set(azel,verif)
time.sleep(29)
else :
mission= predict.Mission()
print("current time1: ",mission.now,'\n',mission.start,' ',mission.end)
verif1 = mission.verif
end = mission.end
now2 = mission.now
while now2 <= end :
azel = rotator_treshold_test.az_correct(saved[k])
rotator_set(azel,verif1)
saved.append(rotator_treshold_test.az_correct(azel[0]))
k+=1
mission = predict.Mission()
now2 = mission.now
print(now2)
time.sleep(0.8)
##I would like to reboot my script here
while True :
satellite_track()
You could use os.execl() to restart the program.
Source: https://docs.python.org/3/library/os.html#os.execl
I am fairly new to coding, and am currently learning my first language (python) using the book "Learn Python the Hard Way" but this is not a specific exercise in the book and I am just practicing while I am reading code for Exercise 23 and am currently am just trying to figure out if this is even possible...
My first file is pr1.py:
def func():
a = float(raw_input("Enter Your Age:"))
b = float(raw_input("Enter Your Weight:"))
c = float(raw_input("Enter Your Height:"))
age = "a"
weight = "b"
height = "c"
if __name__ == "__main__":
print("This is pr1.py")
else:
print("%s is being imported to another file") % __name__
My second file is pr2.py
import pr1
def func():
x = raw_input("Enter Your Race:")
y = raw_input("Enter Your Gender:")
z = raw_input("Enter Your Language:")
print "Lets find your numbers"
pr1.func()
print "Lets find your identity"
func()
race = "x"
gender = "y"
language = "z"
if __name__ == "__main__":
print("This is pr2.py")
else:
print("%s is being imported into another file") % __name__
This is my 3rd file pr3.py
import pr1
print "%s = a %s = b %s = c" % (age, weight, height)
import pr2
print "%s = x, %s = y, %s = z" % (race, gender, language)
When I run pr3.py and comment out the scripts to "print" line 3 and line 7 this is what i get:
python pr3.py
pr1 is being imported to another file
Lets find your numbers
Enter Your Age:25
Enter Your Weight:224
Enter Your Height:76
Lets find your identity
Enter Your Race:white
Enter Your Gender:male
Enter Your Language:english
pr2 is being imported into another file
and I am expecting the pr3.py file to print those statement's with the previously defined variable's.
but instead it comes up with this error:
pr1 is being imported to another file
Traceback (most recent call last):
File "pr3.py", line 3, in <module>
print "%s = a %s = b %s = c" % (age, weight, height)
NameError: name 'age' is not defined
Now when I run my last file in the command, I am expecting it to import the previous 2 files, so I can input the data I put into raw_input, and then use use it in other files... but it seems like once both files get imported and I input the data into their respective raw_input's, it seems as if the pr3.py forget's the raw input and their corresponding variable's.
Please forgive me if I am totally lacking some obvious knowledge that could fix all this, but I am very new to coding and not even a month ago, I didn't even know you could create a directory in the terminal.
Thank's for reading and I would appreciate any help.
Okey, here are a couple of things.
First I will say which obvious things are wrong with your code.
After that I will show you an example of your code, using classes.
So, first:
age, weight, height are all defined in pr1.py, so eiter you need to refer to them as pr1.age, pr1.weight, pr1.height, or you from pr1 import age, weight, height. Same applies for race, gender, language in pr2.py
That said, you might expect to get what you inputted to be printed out. But you only assigned the characters 'a', 'b', 'c', 'x', 'y' and 'z' to those variables.
Also you print age, weight and height before you even run func() in pr2.py
So second: how do we fix this. First you need to think about in which order things are happening, when you do imports. Also you need to think about, if the variables you refer to, really are set anywhere.
In this case you set your raw_input's to variables insde a function, and they will only be accessible inside that function.
This can be fixed by using globals, or by making an object. I will reccommend using object (classes).
Since you say you are fairly new to programming, classes might seem over your head now, but when you get it, it solves alot of these problems.
Also you will get to classes soon enough in Learn Python The Hard Way soon enough.
To take your code as example:
pr1.py:
class Numbers:
def func(self):
self.age = float(raw_input("Enter Your Age:"))
self.weight = float(raw_input("Enter Your Weight:"))
self.height = float(raw_input("Enter Your Height:"))
if __name__ == "__main__":
print("This is pr1.py")
else:
print("%s is being imported to another file") % __name__
pr2.py:
from pr1 import Numbers
class Identity:
def func(self):
self.race = raw_input("Enter Your Race:")
self.gender = raw_input("Enter Your Gender:")
self.language = raw_input("Enter Your Language:")
print "Lets find your numbers"
nrs = Numbers()
nrs.func()
print "Lets find your identity"
ids = Identity()
ids.func()
if __name__ == "__main__":
print("This is pr2.py")
else:
print("%s is being imported into another file") % __name__
pr3.py:
from pr2 import *
print "%s = a %s = b %s = c" % (nrs.age, nrs.weight, nrs.height)
print "%s = x, %s = y, %s = z" % (ids.race, ids.gender, ids.language)