Skype4py attach does not work - python

I am having trouble with getting Skype4Py to attach to my Skype client. I downloaded easy _install and used it to install Skype4Py. I have 64bit Python and windows 7. When I try the example script (seen below) line by line using the IDLE, I can't get past the skype.attach(), nothing seems to happen. I end up having to close the IDLE and kill the application. If you have any ideas please let me know. I apologize in advance. Just figuring out how to download Skype4Py was challenging for me. Skype is running and I am logged in.
import Skype4Py
# Create an instance of the Skype class.
skype = Skype4Py.Skype()
# Connect the Skype object to the Skype client.
skype.Attach()
# Obtain some information from the client and print it out.
print 'Your full name:', skype.CurrentUser.FullName
print 'Your contacts:'
for user in skype.Friends:
print ' ', user.FullName

Currently looks like 64-bit Python is not supported, because Skype the client application is 32-bit.
https://github.com/awahlig/skype4py/issues/6
Use 32-bit Python.

Related

How to check if a minecraft server is online and get info of stats (like number of players online) using Discord py

I have a bot that works in a discord server for a minecraft server.
I want to make one of the bot's command to ping the minecraft server to check if it is up (or even get stats like number of players).
Does anybody know of a way to ping a mc server and even get stats from said server?
This is possible! You can use Dinnerbone's own implementation.
This basic Python script should do what you want (using hypixel as an example):
from mcstatus import MinecraftServer
server = MinecraftServer.lookup("mc.hypixel.net")
status = server.status()
print("The server has {0} players and replied in {1} ms".format(status.players.online, status.latency))
latency = server.ping()
print("The server replied in {0} ms".format(latency))
There's heaps more you can do, check it out: https://github.com/Dinnerbone/mcstatus
You can install this package by running:
python3 -m pip install mcstatus
Also note that according to the Github repo, this will only work on servers above version 1.7 :)
You can do that with SourceQuery - pick the code from github and you can import that in your DC Bot and it gives you all the information any GoldSRC Server can give you, MC works with it as well.
https://github.com/olli-e/ISRT-Insurgency-Sandstorm-RCON-Query-Tool/blob/main/bin/SourceQuery.py
You will find an example usage at the end of the script.
You can also use mcrcon, but I assume you want to wrap it in python.

Sending automated email using Pywin32 & outlook in a python script works but when automating it through windows task scheduler doesn't work

I wrote a python script that uses win32com.client.Dispatch("Outlook.Application") to send automated emails through outlook.
If I run the script myself everything works perfectly fine. But if I run it through Window's task scheduler it doesn't send the emails.
Just to check if I am running the script properly I made the script output a random text file and that works but email doesn't. Why?
Do you add any attachments to an email before you send it? I had a similar problem but it is working perfectly now. If I had two different functions in my script to send emails (for example one to send an email in the event of an error, and one to send an email if the script ran successfully) I would get an 'operation aborted' error from Outlook. This was because in one of the functions I would add an attachment to the email, however in the other function I wouldn't. Don't ask me why but this would cause an error. To resolve I just had to add a redundant attachment to the email that didn't need an attachment.
def emailComplete():
ol = DispatchEx("Outlook.Application")
Msg = ol.CreateItem(0)
Msg.To = "recip#ient.com"
Msg.Subject = "foo complete"
Msg.Attachments.Add("C:\Path\to\blank\attachment.txt") # send a blank attachment to stop the 'operation aborted' error
Msg.Send()
ol.Quit()
def emailError():
ol = DispatchEx("Outlook.Application")
Msg = ol.CreateItem(0)
Msg.To = "recip#ient.com"
Msg.Subject = "foo errored"
Msg.Attachments.Add("C:\path\to\error\file.txt") # send the error file with the email
Msg.Send()
ol.Quit()
It's not the most elegant solution, but it's got mine working!!
My similar issue has been cleared up. I used task scheduler to call a python script (via batch file) that has the pywin32com module. The python code opens excel and calls a macro. It will run fine from python, cmd and the batch file, but wasn't working when ran through task scheduler. It traced back to errors like:
"EnsureDispatch disp = win32com.client.Dispatch(prog_id)"
As noted on this thread, I changed the option to "Run only when user is logged on" and it ran successfully!
The only drawback is that I schedule the task for a time that I'm away from the computer. I suppose I just have to not log off and hope that the cpu doesn't go into sleep mode, but that's not really a big deal in this case.
I had the same issue with an Excel application I built. When executed during my trouble-shooting I would get an Outlook profile dialog box that I couldn't circumvent. Oddly enough, this dialog box wouldn't appear during scheduled execution. I found a way around this and that was to send email using CDO. I understand that you're not using VBA but this could point you to an alternate method of sending an email (like what I had to do):
http://www.rondebruin.nl/win/s1/cdo.htm
Note: I was only able to have success when I set the Security Option to "Run only when user is logged on" (I have full admin rights on my machine and am running w/highest privileges). I have a strong -- but unconfirmed -- suspicion that there is some security setting invoked when the Task Scheduler is involved, at least in a corporate environment.

Run Python application from browser

I'm pretty new to programming and I've been learning python in my spare time. As a challenge to myself, I created a simple text adventure for a class project. This is not for a programming class, so the professor won't know how to compile a raw Python script, let alone have a Python interpreter on their Mac.
That being said, is it possible to run python from a browser? I'm imagining some HTML file that my professor, or anyone, can click that launches a browser and they can play my game from there.
I've learned about something called Django from my research on this subject. However, I have no idea what it is, nor how to implement it. Again, I'm pretty new to programming, so if you could "explain like I'm five", that would be great.
EDIT: I found this other thread where the OP asks a similar question, but I don't fully understand the approved answer:
execution python application from browser
Well, not really. Your basic browser generally supports 1 programming language, javascript.
However, you could use pythonanywhere" which is a hosted python environment.
You could also try skulpt which is a javacript implementation of python. I have never tried this myself.
You can host a website on an internal network and run the program from there. Read more about the Python CGI programming
here to make a form that will execute your script and print the result as a html page
For example you could have a form that will ask for input in textboxes: Name: _, Value: __, SUBMIT
After they press the button, the browser will then send a request to the python program, execute it, and display the result back to the client as a html webpage.
In addition, you do not need to install any other third-party modules if you are using a school computer. However, ask you teacher before hosting the website on the school network.
The problem is that your program is a "text adventure" which requires a lot more input/output management for a CGI program.
You can use this answer for other projects.
Anyway, here are the steps to setup the server:
1) Create a folder for your website and add a "index.html" file (it can be anything)
2) Add a favicon.ico file in the folder (this will speed up the connection) You can download this one
3) Put this python program in the folder (it will be used to host the website)
import BaseHTTPServer
import CGIHTTPServer
import cgitb; cgitb.enable()
from socket import gethostbyname, gethostname
def server(port):
server = BaseHTTPServer.HTTPServer
handler = CGIHTTPServer.CGIHTTPRequestHandler
server_address = ("", port)
httpd = server(server_address, handler)
print "Server %s:%s started" % (gethostbyname(gethostname()), str(port))
httpd.serve_forever()
server(4) #You can change this. It is a port number
4) Create a cgi-bin folder
5) To make the website available, execute the program created in the step 3. To stop hosting it, just close the python console.
6) While the program is running, you can go into the browser and type the IP adress : port as the URL. You will see your index.html page and favicon.ico icon. Anyone who is connected to the same network can get to the website. You and only you can also get to the website in a browser by entering http:/localhost:port with "port" being the port you've set
7) The rest you need to manage yourself. I cannot create the full script because I do not know what is in your program. Read the link provided in the beginning and modify your program to make it work in the browser.
FYI: It is possible to host more than one website or an instance of the same website at once using different ports. And, you can set and read cookies using Python CGI
Please comment if something doesn't work because of an error in my answer. I will try to fix it.
All of the answers so far assume that your game is something that can be presented as a web app. You can only do that if you write or covert your program (or part of it) into Javascript, which may not actually work because the existing compilers (e.g. pyjs) are quite limited.
If you made your program in a GUI (using 'Tkinter', 'Pygame', wxPython, PyQt, etc.), your best option is to package your program into a Mac app using py2app or pyinstaller.

How to ignore CTRL_LOGOFF_EVENT in a python executable on Windows?

I have been searching or an answer, but found nothing sepcific, except for the windows service part.
Is it possible to ignore the LOGOFF signal that Windows sends, when a user is logging off, and keep my python executalbe ( py2exe ) running , besides using windows service?
Or any other way I can keep it running even after an user has logged off? User does NOT have administrator priviliges.
Only services receive CTRL_LOGOFF_EVENT. From MSDN:
Note that this signal is received only
by services. Interactive applications are terminated at logoff, so
they are not present when the system sends this signal.
Since your process is not a service, it will not even receive that signal, hence, it is not possible to "ignore" it.

problem in python script for phone call from skype account

I'm trying to do a phone call by python script from skype account. It runs properly sometime while sometime give segmentation error while sometime it runs without error but no output. I had used following script for this as,
import Skype4Py
import sys
skype = Skype4Py.Skype()
skype.Attach()
m_PhoneNumber = "919763667993"
m_Call = skype.PlaceCall(m_PhoneNumber)
Please give me solution for this, i think it maybe Skype4Py.api.posix_dbus.SkypeAPI Thread Problem ,
but not getting solution for this.

Categories

Resources