How to Autenticate on Twitter using Tweepy oauth

Problem: 

You need a way to use diferent bots using the same developer API.

Solution:

I foun a trick that you can use directly in python with a single script; here the point is that you have to request the PIN on the execution time so you will not able to save the key's on execution time.

1.- Run this code script.

2.- Open the web link after login with your external twitter account to get the PIN code.

3.- Continue execution  after you enter the PIN.

import tweepy
# api credentials 
auth = tweepy.OAuthHandler('api key', 'api secret','oob')
# get access token from the user and redirect to auth URL
auth_url = auth.get_authorization_url()
print('Authorization URL: ' + auth_url)
# ask user to verify the PIN generated in broswer
verifier = input('PIN: ').strip()
auth.get_access_token(verifier)
print('ACCESS_KEY = "%s"' % auth.access_token)
print('ACCESS_SECRET = "%s"' % auth.access_token_secret)
# authenticate and retrieve user name
auth.set_access_token(auth.access_token, auth.access_token_secret)
api = tweepy.API(auth)
user = api.verify_credentials()
print('Name: ' + str(user.name))


Source:

By suracoza
https://gist.github.com/hezhao/4772180#gistcomment-3972371

Python, use proxy for Selenium test automation

Problem:

You need to make a test script using Selenium with python in a raspberry pi and you don't know how to use it.

Solution:

Copy and paste the following code in your py file:

from selenium import webdriver

from selenium.webdriver.common.keys import Keys

from fp.fp import FreeProxy

import os


#proxy connection 

try:

 v_proxy = FreeProxy(timeout=0.3, anonym=False, rand=True).get()

 if(v_proxy!=""):

  print(' Using Proxy: ', v_proxy)

except Exception as e:

 print(' Error:', e)


#load data

chrome_options = webdriver.ChromeOptions()

chrome_options.add_argument('--proxy-server=%s' % v_proxy)

chrome_options.add_argument("--incognito")

driver = webdriver.Chrome(options=chrome_options)

driver.get("https://www.whatismyip.com/es/")


Mostrar información del sistema en el inicio de sesión SSH

Es muy útil iniciar sesión para verificar nada más entrar en nuestra Raspberry Pi el estado del sistema, por lo que no sería bueno tener algunos parámetros importantes del sistema, tales como la carga, el tiempo de actividad, la memoria RAM disponible, etc...

Veamos una solución basada en un script de Shell que nos da la información actual del sistema justo después de inicar sesión SSH a través del Mensaje del día, también conocido como MOTD.

Veamos un ejemplo:


Es posible añadir un texto ASCII con generadores ASCII como este: aquí .

Como crear nuestro propio MOTD ?

Primero vamos a crear nuestro propio mensaje dinámico.

Para ello crearemos un archivo con este nombre “dynmotd” en  la siguiente ruta “/ usr / local / bin” y lo editamos con un editor para añadir la información que queremos

sudo nano /usr/local/bin/dynmotd