This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2, queue, threading, time | |
import boto3 | |
from botocore.exceptions import ClientError | |
import io | |
import RPi.GPIO as GPIO | |
import imutils | |
# Video streaming URL | |
webcam_url = 'rtsp://user:pwd@192.168.1.1:554/11' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cap = VideoCapture(webcam_url) | |
model = cv2.dnn.readNetFromTensorflow('models/frozen_inference_graph.pb', | |
'models/ssd_mobilenet_v2_coco_2018_03_29.pbtxt') | |
# Get a frame | |
frame = cap.read() | |
# Submit it to model | |
model.setInput(cv2.dnn.blobFromImage(frame, size=(300, 300), swapRB=True)) | |
output = model.forward() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Find rectangles in image and return a list of cropped images. | |
def extract_rectangles(image): | |
result = [] | |
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | |
gray = cv2.bilateralFilter(gray, 11, 17, 17) | |
edged = cv2.Canny(gray, 30, 200) | |
cnts = cv2.findContours(edged.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) | |
cnts = imutils.grab_contours(cnts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def detect_text(photo, bucket): | |
"""Detect text in an image hosted as bucket object | |
:param phone: Object name | |
:param bucket: Bucket name | |
:return: | |
""" | |
client=boto3.client('rekognition') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: Install apache2 packages | |
apt: | |
name: apache2 | |
state: present | |
- name: Ensure Apache is running | |
service: | |
name: apache2 | |
state: started | |
enabled: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import pytest | |
import testinfra.utils.ansible_runner | |
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( | |
os.environ['MOLECULE_INVENTORY_FILE'] | |
).get_hosts('all') | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo: required | |
language: python | |
python: | |
- '3.6' | |
install: | |
- pip install -r test-requirements.txt | |
env: | |
global: | |
- EC2_REGION=eu-west-1 | |
script: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def request_certs(emails, domains): | |
''' Request a new cert for specified domain, hosted in a public access S3 bucket. | |
'auth-hook.py' script is used in validation, to upload Certbot token to the bucket | |
'cleanup-hook.py' script is used after validation to remove token file in bucket | |
''' | |
certbot_args = [ | |
# Override directory paths to use /tmp folder | |
'--config-dir', '/tmp/certbot/config', | |
'--work-dir', '/tmp/certbot/work', | |
'--logs-dir', '/tmp/certbot/logs', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def update_symlinks(domain): | |
''' The dark side of the symlinks, required by Certbot and not restored by | |
zipfile. This method recreates symlinks for specified domain, removing | |
regular files. | |
''' | |
for k in ['cert', 'chain', 'privkey', 'fullchain']: | |
try: | |
os.remove('/tmp/certbot/config/live/{}/{}.pem'.format(domain,k)) | |
except: | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def upload_auth(): | |
''' Write token file and upload it to correct S3 bucket and folder | |
S3 Bucket name and cert domain must be the same! | |
''' | |
f = open("/tmp/verification.txt", "w") | |
f.write(os.environ['CERTBOT_VALIDATION']) | |
f.close() | |
s3object = ".well-known/acme-challenge/" + os.environ['CERTBOT_TOKEN'] | |
upload_file("/tmp/verification.txt", os.environ['CERTBOT_DOMAIN'], s3object) |
OlderNewer