domingo, 25 de agosto de 2019

Python if else

amount=13
if amount<1000:
   discount = amount*0.05
   print ("Discount",discount)

elif amount==1000:
    print ("Net payable:",amount-discount)


else:
   discount = amount*0.15
   print ("Discount",discount)


viernes, 26 de julio de 2019

domingo, 7 de julio de 2019

python gmail smtplib


The issue is in pip. I was unable to update setuptools using
easy_install --upgrade setuptools
I was also unable to install email with pip using
pip install email
I fixed the problem by installing email using easy_install
easy_install email

import smtplib

gmail_user = 'ambiorixg13'
gmail_password = '111112231'

sent_from = gmail_user
to = ['me@gmail.com', 'ambiorixg12@gmail.com']
subject = 'OMG Super Important Message'
body = ('Hey, what')

email_text = """\
From: %s
To: %s
Subject:  testing %s

%s
""" % (sent_from, ", ".join(to), subject, body)

try:
    server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
    server.ehlo()
    server.login(gmail_user, gmail_password)
    server.sendmail(sent_from, to, email_text)
    server.close()

    print ('Email sent!')
except:
    print ('Something went wrong...')

martes, 28 de mayo de 2019

Audio configuration


The Raspberry Pi has two audio output modes: HDMI and headphone jack. You can switch between these modes at any time.
If your HDMI monitor or TV has built-in speakers, the audio can be played over the HDMI cable, but you can switch it to a set of headphones or other speakers plugged into the headphone jack. If your display claims to have speakers, sound is output via HDMI by default; if not, it is output via the headphone jack. This may not be the desired output setup, or the auto-detection is inaccurate, in which case you can manually switch the output.

Changing the audio output

There are three ways of setting the audio output.

Desktop volume control

Right-clicking the volume icon on the desktop taskbar brings up the audio output selector; this allows you to select between the internal audio outputs. It also allows you to select any external audio devices, such as USB sound cards and Bluetooth audio devices. A green tick is shown against the currently selected audio output device — simply left-click the desired output in the pop-up menu to change this. The volume control and mute operate on the currently selected device.

Command line

The following command, entered in the command line, will switch the audio output to HDMI:
amixer cset numid=3 2
Here the output is being set to 2, which is HDMI. Setting the output to 1switches to analogue (headphone jack). The default setting is 0 which is automatic.

raspi-config

Open up raspi-config by entering the following into the command line:
sudo raspi-config
This will open the configuration screen:
raspi-config screen
Select Option 8 Advanced Options and press Enter, then select Option A6: Audio and press Enter:
Audio configuration screen
Now you are presented with the two modes explained above as an alternative to the default Auto option. Select a mode, press Enter and press the right arrow key to exit the options list, then select Finish to exit the configuration tool.

If you're still not getting sound via HDMI

In some rare cases, it is necessary to edit config.txt to force HDMI mode (as opposed to DVI mode, which does not send sound). You can do this by editing /boot/config.txt and setting hdmi_drive=2, then rebooting for the change to take effect.

domingo, 24 de marzo de 2019

python AMI event filter

#!/usr/bin/python
import os
import time
from settings import login, connection

from asterisk.ami import AMIClient

client = AMIClient(address='127.0.0.1',port=5038)
client.login(username='admin',secret='2256')


def event_listener(event,**kwargs):

       #print(vars(event))  ## print all info
    print(event[u'Channel'])  ##print only the channel name key
client.add_event_listener(
    event_listener,
    white_list='Newstate',
    ChannelStateDesc='Ringing'
)


client = AMIClient(**connection)
future = client.login(**login)
if future.response.is_error():
    raise Exception(str(future.response))


try:
    while True:
        time.sleep(10)
except (KeyboardInterrupt, SystemExit):
    client.logoff()

https://github.com/ettoreleandrotognoli/python-ami/blob/master/README.rst
https://pypi.org/project/asterisk-ami/

Python Socket

https://realpython.com/python-sockets/