Python Grundstrucktur
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
#!/usr/bin/env python # -*- coding: utf-8 -*- ################################################### # Program......: main.py # Creation.....: 03.07.2016 # Last Update..: 19.07.2016 # # Copyright (c) 2015-2015 by banto@gmx.net # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. ################################################### import os import time import RPi.GPIO as GPIO from datetime import datetime import sys LOW = False HIGH = True GPIO.setmode(GPIO.BCM) # GPIO Pin's zuordnen PIN1 = 20 PIN2 = 10 GPIO.setup(PIN1, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(PIN2, GPIO.OUT) def main(): try: GPIO.setmode(GPIO.BCM) while True: if GPIO.input(PIN1)==True: GPIO.output(PIN2,GPIO.HIGH) else: GPIO.output(PIN2,GPIO.LOW) except KeyboardInterrupt: print("Program stopped by user") GPIO.cleanup() if __name__ == '__main__': main() |
Python send URL
1 2 3 4 5 6 7 |
#!/usr/bin/env python # -*- coding: utf-8 -*- # import requests url = 'https://api.github.com/user' r = requests.get(url, auth=('user', 'pass')) print (r.status_code) |
Python send json Sting POST
Python time function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
%a Abgekürzter Name des Wochentags. %A Vollständiger Name des Wochenstags. %b Abgekürzter Name des Monats. %B Vollständiger Name des Monats. %c Datum und Uhrzeit im Format des lokalen Systems. %d Nummer des Tages im aktuellen Monat [01..31]. %H Stunde im 24-Stunden-Format [00..23]. %I Stunde im 12-Stunden-Format [01..12]. %j Nummer des Tages im Jahr [001..366]. %m Nummer des Monats [01..12]. %M Minute [00..59]. %p Die lokalisierte Form für AM beziehungsweise PM. %S Sekunde [00..61]. %U Nummer der aktuellen Woche im Jahr [00..53]. Der Sonntag ist der erste Tag der Woche. Der Zeitraum vor dem ersten Sonntag Im Jahr wird als 0. Woche gewertet. %w Nummer das aktuellen Tages in der Woche [0..6]. Der Sonntag wird als 0. Tag betrachtet. %W Wie %U, nur dass der Montag der erste Tag der Woche ist. %x Datum im Format des lokalen Systems. %X Zeit im Format des lokalen Systems. %y Jahreszahl ohne Jahrhundertangabe [00..99]. %Y Jahreszahl mit Jahrhundertangabe. %Z Name der lokalen Zeitzone oder ein leerer String, wenn keine lokale Zeitzone festgelegt wurde. %% Erzeugt ein Prozentzeichen. |
1 2 3 4 |
#!/usr/bin/env python # import time print(time.strftime("%d.%m.%Y %H:%M:%S")) |
Python