Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Powers authored and Mark Powers committed Jul 31, 2020
0 parents commit 0bf7a8d
Show file tree
Hide file tree
Showing 1,227 changed files with 119,918 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
Binary file added 9781484257920.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions Ch01/apd.sensors-chapter01/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[[source]]
name = "piwheels"
url = "https://piwheels.org/simple"
verify_ssl = true

[dev-packages]
ipykernel = "*"
remote-ikernel = "*"

[packages]
psutil = "*"
click = "*"
adafruit-circuitpython-dht = {markers = "'arm' in platform_machine",version = "*"}

[requires]
535 changes: 535 additions & 0 deletions Ch01/apd.sensors-chapter01/Pipfile.lock

Large diffs are not rendered by default.

60 changes: 60 additions & 0 deletions Ch01/apd.sensors-chapter01/sensors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env python
# coding: utf-8
import socket
import sys

import click
import psutil


def python_version():
return sys.version_info


def ip_addresses():
hostname = socket.gethostname()
addresses = socket.getaddrinfo(socket.gethostname(), None)

address_info = []
for address in addresses:
address_info.append((address[0].name, address[4][0]))
return address_info


def cpu_load():
return psutil.cpu_percent(interval=0.1) / 100


def ram_available():
return psutil.virtual_memory().available


def ac_connected():
return psutil.sensors_battery().power_plugged


def get_relative_humidity():
try:
# Connect to a DHT22 sensor on pin 4
from adafruit_dht import DHT22
from board import D4
except (ImportError, NotImplementedError):
# No DHT library results in an ImportError.
# Running on an unknown platform results in a NotImplementedError when getting the pin
return None
return DHT22(D4).humidity


@click.command(help="Displays the values of the sensors")
def show_sensors():
click.echo("Python version: {0.major}.{0.minor}".format(python_version()))
for address in ip_addresses():
click.echo("IP addresses: {0[1]} ({0[0]})".format(address))
click.echo("CPU Load: {:.1%}".format(cpu_load()))
click.echo("RAM Available: {:.0f} MiB".format(ram_available() / 1024**2))
click.echo("AC Connected: {!r}".format(ac_connected()))
click.echo("Humidity: {!r}".format(get_relative_humidity()))


if __name__ == '__main__':
show_sensors()
158 changes: 158 additions & 0 deletions Ch01/figure01-01-fizzbuzz.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1\n",
"2\n",
"Fizz\n",
"4\n",
"Buzz\n",
"Fizz\n",
"7\n",
"8\n",
"Fizz\n",
"Buzz\n",
"11\n",
"Fizz\n",
"13\n",
"14\n",
"FizzBuzz\n",
"16\n",
"17\n",
"Fizz\n",
"19\n",
"Buzz\n",
"Fizz\n",
"22\n",
"23\n",
"Fizz\n",
"Buzz\n",
"26\n",
"Fizz\n",
"28\n",
"29\n",
"FizzBuzz\n",
"31\n",
"32\n",
"Fizz\n",
"34\n",
"Buzz\n",
"Fizz\n",
"37\n",
"38\n",
"Fizz\n",
"Buzz\n",
"41\n",
"Fizz\n",
"43\n",
"44\n",
"FizzBuzz\n",
"46\n",
"47\n",
"Fizz\n",
"49\n",
"Buzz\n",
"Fizz\n",
"52\n",
"53\n",
"Fizz\n",
"Buzz\n",
"56\n",
"Fizz\n",
"58\n",
"59\n",
"FizzBuzz\n",
"61\n",
"62\n",
"Fizz\n",
"64\n",
"Buzz\n",
"Fizz\n",
"67\n",
"68\n",
"Fizz\n",
"Buzz\n",
"71\n",
"Fizz\n",
"73\n",
"74\n",
"FizzBuzz\n",
"76\n",
"77\n",
"Fizz\n",
"79\n",
"Buzz\n",
"Fizz\n",
"82\n",
"83\n",
"Fizz\n",
"Buzz\n",
"86\n",
"Fizz\n",
"88\n",
"89\n",
"FizzBuzz\n",
"91\n",
"92\n",
"Fizz\n",
"94\n",
"Buzz\n",
"Fizz\n",
"97\n",
"98\n",
"Fizz\n",
"Buzz\n"
]
}
],
"source": [
"for num in range(1, 101):\n",
" val = ''\n",
" if num % 3 == 0:\n",
" val += 'Fizz'\n",
" if num % 5 == 0:\n",
" val += 'Buzz'\n",
"\n",
" if not val:\n",
" val = str(num)\n",
"\n",
" print(val)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "advancedpython",
"language": "python",
"name": "advancedpython"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
58 changes: 58 additions & 0 deletions Ch01/figure01-04-versioninfo.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"scrolled": false,
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"data": {
"text/plain": [
"sys.version_info(major=3, minor=8, micro=0, releaselevel='final', serial=0)"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import sys\n",
"sys.version_info"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "advancedpython",
"language": "python",
"name": "advancedpython"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 0bf7a8d

Please sign in to comment.