The comparison operator is ==
, not =
:
...aggregate['2'].shift(1) == aggregate['3']), ...
^
^ here
You need a double equals sign:
aggregate['1'] = np.where(np.logical_and(aggregate['Counter'] > 1, aggregate['2'].shift(1) == aggregate['3']), 0, aggregate['2']
The comparison operator is ==, not =:,I know this error message has been discussed anycodings_numpy on here before but I still cannot figure out anycodings_numpy how to make this work. I'm trying to do a anycodings_numpy np.where statement with more than one anycodings_numpy condition. Below is my code. I am getting anycodings_numpy the error message "Keyword can't be an anycodings_numpy expression" and it is highlighting the space anycodings_numpy after "aggregate['Counter'] > 1.,Is there any way in python to create list using key value pairs,Why are these constructs using pre and post-increment undefined behavior?
I know this error message has been discussed anycodings_numpy on here before but I still cannot figure out anycodings_numpy how to make this work. I'm trying to do a anycodings_numpy np.where statement with more than one anycodings_numpy condition. Below is my code. I am getting anycodings_numpy the error message "Keyword can't be an anycodings_numpy expression" and it is highlighting the space anycodings_numpy after "aggregate['Counter'] > 1.
aggregate['1'] = np.where(np.logical_and(aggregate['Counter'] > 1, aggregate['2'].shift(1) = aggregate['3']), 0, aggregate['2'])
The comparison operator is ==, not =:
...aggregate['2'].shift(1) == aggregate['3']), ...
^
^ here
You need a double equals sign:
aggregate['1'] = np.where(np.logical_and(aggregate['Counter'] > 1, aggregate['2'].shift(1) == aggregate['3']), 0, aggregate['2']
Python - "Keyword cannot be an expression",pandas.concat: Cannot handle a non-unique multi-index! Pandas Python,Python pandas cannot read old excel files with some strange encoding and split panes,cannot sum rows that match a regular expression in pandas / python
The comparison operator is ==
, not =
:
...aggregate['2'].shift(1) == aggregate['3']), ...
^
^ here
You need a double equals sign:
aggregate['1'] = np.where(np.logical_and(aggregate['Counter'] > 1, aggregate['2'].shift(1) == aggregate['3']), 0, aggregate['2']
But the command the start ‘default_radio_station.m3u’ is resulting in 'keyword cannot be an expression. When I run the command below in a SSH session it does work. xbmc-send --action="PlayMedia(/home/osmc/kitchen_extras/default_radio_station.m3u)",On long press: stop playing ‘default_radio_station.m3u’, start playing a shuffled playlist (preferred from Spotify (seems difficult) so to start with it would be nice to play a .m3u file).,On short press: stop what’s playing (both from inside Kodi and Spotify (via http://:4000/api/playback/pause)), start playing ‘default_radio_station.m3u’,Could someone give me a hint in the right direction? If I could get the command on the bottom line working I plan to reuse the restart/shutdown script to get both function ‘1’ and ‘2’.
For ‘1’ I currently have:
import RPi.GPIO as GPIO
import time
import os
#adjust
for where your
switch is connected
buttonPin = 8
GPIO.setmode(GPIO.BCM)
GPIO.setup(buttonPin, GPIO.IN)
while True:
#assuming the script to call is long enough we can ignore bouncing
if (GPIO.input(buttonPin)):
#this is the script that will be called(as root)
os.system(xbmc - send--action = "PlayMedia(/home/osmc/kitchen_extras/default_radio_station.m3u)")
The script for the Restart/shutdown button:
#!/bin/python #This script was authored by AndrewH7 and belongs to him(www.instructables.com / member / AndrewH7) #You have permission to modify and use this script only for your own personal usage #You do not have permission to redistribute this script as your own work #Use this script at your own risk import RPi.GPIO as GPIO import time import os gpio_pin_number = 7 #Replace YOUR_CHOSEN_GPIO_NUMBER_HERE with the GPIO pin number you wish to use #Make sure you know which rapsberry pi revision you are using first #The line should look something like this e.g. "gpio_pin_number=7" GPIO.setmode(GPIO.BCM) #Use BCM pin numbering(i.e.the GPIO number, not pin number) #WARNING: this will change between Pi versions #Check yours first and adjust accordingly GPIO.setup(7, GPIO.IN, pull_up_down = GPIO.PUD_UP) #It 's very important the pin is an input to avoid short-circuits #The pull - up resistor means the pin is high by default button_previous = 1 button_current = 1 brojac = 0 flag_pressed = 0 while True: button_current = GPIO.input(7); flag_pressed = button_previous + button_current if (not(flag_pressed)): brojac += 1 else: brojac = 0 if (button_current and(not button_previous)): os.system("sudo shutdown -r now") if ((not flag_pressed) and brojac >= 100): os.system("sudo shutdown -h now") break button_previous = button_current time.sleep(0.05) GPIO.cleanup() #Revert all GPIO pins to their normal states(i.e.input = safe)
For ‘1’: ‘xbmc-send.stop_play_radio.sh’ with the following content:
#!/bin/bash
(curl http://<IP>:4000/api/playback/pause; xbmc-send --action="PlayMedia(/home/osmc/kitchen_extras/default_radio_station.m3u)")
And for ‘2’: ‘xbmc-send.stop.sh’ with the following content:
#!/bin/bash xbmc - send--action = "stop"
Now I can almost see the finish line .
I reused the script for the restart/shutdown button, included two parameters which point to the new bash scripts:
script_short_press = "sh ./home/osmc/kitchen_extras/xbmc-send.stop_play_radio.sh"
script_long_press = "sh ./home/osmc/kitchen_extras/xbmc-send.stop.sh"
After some more searching I found the script below and edited it for my usage. The script doesn’t look as neat as the script for the restart/shutdown button but it works .
#!/usr/bin/env python2.7 from time import sleep import subprocess import RPi.GPIO as GPIO CHANNEL = 11 # GPIO channel 11 is on pin 23 of connector P1 # it will work on any GPIO channel GPIO.setmode(GPIO.BCM) GPIO.setup(CHANNEL, GPIO.IN, pull_up_down = GPIO.PUD_UP) # setup the channel as input with a 50 K Ohm pull up.A push button will ground the pin, # creating a falling edge. def system_action(CHANNEL): print('Button press = negative edge detected on channel %s' % CHANNEL) button_press_timer = 0 while True: if (GPIO.input(CHANNEL) == False): # while button is still pressed down button_press_timer += 1 # keep counting until button is released else: # button is released, figure out for how long if (button_press_timer > 2): # pressed for > 2 seconds print "long press > 2 : ", button_press_timer # do what you need to do before the command below subprocess.call("/home/osmc/kitchen_extras/xbmc-send_stop.sh", shell = True) elif(button_press_timer > 0): # press for > 0 < 2 seconds print "short press > 0 < 2 : ", button_press_timer # do what you need to do before the command below subprocess.call("/home/osmc/kitchen_extras/xbmc-send_stop_play_radio.sh", shell = True) button_press_timer = 0 sleep(1) GPIO.add_event_detect(CHANNEL, GPIO.FALLING, callback = system_action, bouncetime = 200) # setup the thread, detect a falling edge on channel 11 and debounce it with 200 mSec # assume this is the main code... try: while True: # do whatever # while "waiting" for falling edge on port 11 sleep(2) except KeyboardInterrupt: GPIO.cleanup() # clean up GPIO on CTRL + C exit GPIO.cleanup() # clean up GPIO on normal exit