sending Facebook messages with python script - python

i'm trying to find a way to send Facebook messages using a python scripts on my computer (e.g. something like send_msg(user_id, msg)). I figured the Facebook API would make this process easy but i was wrong (i don't have much experience with APIs). It seems the only way to automate sending messages is to host the script (flask app) on some server (e.g. Heroku) where Facebook will communicate exclusively with it and bypass my computer all together. I want to know if this really is the only way of communicating with the Facebook API.

Related

How to send push notifications to iOS using a python api

I have create a webscraper that sends notifications to my phone whenever certain events are detected. So far I have achieved this by sending emails through the sendgrid api. Its a pretty nice service, and it is free, but it clutters up the mailbox quite a bit.
In stead Iā€™d like to send messages directly to the iOS notification bar. Does anyone here has experience with sending push-notifications to iOS and can point me in the correct direction? I would be happy with a subscription service, but would off course prefer a solution that does not require a third party if it is possible.
I have tested PushNotifier, but I found it a bit clunky, and the notifications are neither customisable or beautiful. Its also not a free service, which would have been a great plus.
Maybe you should check out pushover.net. They have a simple WebAPI to send customized notifications to iOS devices.
See https://support.pushover.net/i44-example-code-and-pushover-libraries#python for code samples.

Google Assistant API, controlling a light switch connected to Google Home

I have machine A that just cranks out .png files. It gets synced to machine B and I view it on machine B.
Sometimes machine A crashes for whatever reason and stops doing the scheduled jobs, which means then files on machine B will be old.
I want machine B to run a script to see if the file is older than 1 day, and if it is, then reset the power switch on machine A, so that it can be cold booted. The switch is connected to Google Home but understand I have to use the Assistant API.
I have installed the google-assistant-sdk[samples] package. Can someone show me some code on how to query and return all devices then flip the switch on and off on that device?
Unfortunately, many smart home companies are building products for consumers, not developers. Google's SDK is letting developers stream consumer voice requests to their servers and turning that into actions. Gosund, similarly, is only interested in API access for Amazon and Google. They're API is probably not documented for public use.
To answer your specific question, if you want to use the Google Assistant SDK, you would name your switch something like "Server A Switch" and record a short clip of you saying "Turn off Server A Switch" and "Turn on Server A Switch" and send those two google. The way google matches the requests with your particular account is through OAuth2 tokens, which google will give you in exchange for valid sign in credentials.
If Gosund works with Google Assistant, it has a standard OAuth2 server endpoint as well as a Google Assistant compliant API endpoint. I only recommend this if you want to have some fun reverse engineering it.
In your Google Assistant app, if you try adding the Gosund integration, the first screen popup is the url endpoint where you can exchange valid Gosund account credentials for a one-time code which you can then exchange for OAuth2 access and refresh tokens. With the access token you can theoretically control your switch. The commands you'll want to send are standardized by Google. However, you'll have to figure out where to send them. The best bet here is probably to email their developers.
Are you familiar with OAuth2? If not, I don't recommend doing any of the above.
Your other option is to prevent Server A from hardware crashes. This is what I recommend as the least amount of work. You should start with a server that never crashes, keep it that way and add stuff on top of it. If you only have two servers, they should be able to maintain many months of uptime. Run your scheduled jobs using cron or systemctl and have a watchdog that restarts the job when it detects an error. If your job is crashing the server maybe put it in a VM like docker or something, which gives you neat auto-restart capabilities off the bat.
Another hacky thing you can do is schedule your gosund plug to turn off and on once a day through their consumer UI or app, or at whatever frequency you feel like is most optimal.
The google-assistant-sdk is intended for processing audio requests.
From the doc:
Your project captures an utterance (a spoken audio request, such as What's on my calendar?), sends it to the Google Assistant, and receives a spoken audio response in addition to the raw text of the utterance.
While you could use that with some recorded phrases it makes more sense to connect to the switch directly or use a service like IFTTT. What kind of switch is it?

Is there a way to make a site to display the uptime and output of a long running python program

I have multiple discord bots that I make and host for people. I was looking to make a page on my website to show the stdout, stderr and uptime of each of my bots on this page.
Each bot runs in a separate "screen", which is created using the screen package as provided: here
I can easily pipe the stdout and stderr to any file if needed.
I am running ubuntu 18.04 and I personally own the machine so there are little to no limitations on what I am able to do with it.
My python version is: Python 3.6.4
The discord bot API is discord.py v1.4.1 (rewrite) as seen: here
v1.5.0 is newly released so I'm waiting to update to it, while checking the changelog I didn't notice anything that could affect this project so there should be no issues
I am not concerned about the layout of the website as all styling will be done later, I just want to see if there is a way that I can take the values specified above and put them in a web page. I have some experience in js and am quite experienced in theoretical knowledge, so not knowing exactly how to code in it shouldn't be too much of a problem (I hope)
I have searched around for a while but couldn't find any solutions. Hope someone here can help :)
Uptime monitoring websites is not directly a feature of discord.py, because it would add a whole layer of complexity šŸ˜”.
You can write your own HTTP web server to serve your website's content (ie. to keep track of uptime, downtime, etc. by yourself šŸ˜«), but that would probably end up being overly complicated.
If you don't want this extreme complexity, you can use āš’ļø UptimeRobot (not affiliate link) to create a status page for you. All you have to do is open an HTTP endpoint on the same server that's running your Discord bot (preferably in the same process, maybe a different thread), so UptimeRobot knows when your Discord bot comes šŸŸ¢ online and goes šŸ”“ offline.
To create the HTTP endpoint, you can use the built in http.server module, or šŸ› ļø Flask. Note that, in order for UptimeRobot to make a connection with the server hosting the Discord bot, port forwarding needs to be done. If you don't have access to the network, you can use a service like šŸ§° ngrok to publicly expose the port the server is running on.
All services mentioned above are free šŸ¤‘, and are not affiliate links. šŸ¤—

Implement SMS gateway on django project

I know some SMS API, they are too expensive for the goal of my application.
Is there a way to create an SMS server to alert users, then the user can send feedbacks, my application will easily reply based on some key codes. I heard about Rapid SMS. What comes to my mind:
A modem
SIM card
A daemon software (kannel maybe)
Web application with django
Any help will be gracefull!
Twilio supports sending SMS messages, and I believe it can also carry out certain actions on receiving an SMS. It has a Python API client so it should in principle be practical to integrate it with your application.

Communicating between appengine and an application

I'm working on a web interface which currently runs using PHP and communicates locally to a python script.
I'm moving the web side to appengine, which so far is going well when being used locally, I'm currently communicating from the appengine app to the python app via get requests that are handled by the python script.
The problem is, that obviously the machine running the python script will be behind a firewall, I've never needed to do this before and am not sure on how to implement this best.
The only idea I have so far is for the python script to send post requests to the appengine with some data and then as a response, send back some other data. The only problem with this is that the web interface should update the client quite fast.
Any ideas?
Take a look at ProtoRPC Python API: https://developers.google.com/appengine/docs/python/tools/protorpc/overview
Though it is still marked as experimental, it seems to be a decent framework for what you are trying to do - send messages back and forth between the apps.
Since you said your local app runs behind a firewall, I'm assuming you cannot open up an endpoint and protect it with some form of authentication.
Once you have messages flowing, you can either use Channel API to keep the front-end updated: https://developers.google.com/appengine/docs/python/channel/overview
Or if you want to go more basic, just implement long/short polling through AJAX.
Sorry with the limited amount of info you have provided, that's all I can think of right now. Please feel free to post more details and I'll try to help further.

Categories