Beispiel #1
0
#
from urllib.request import urlopen as uRequest  # collect.py
from bs4 import BeautifulSoup as bSoup  # collect.py
import pymysql  # database.py

from modules.collect import grab100 as grabTopPages
from modules.database import Database

# Grab data
books = grabTopPages()

# Connect to database
db = Database('localhost', 'root', 'pyDB')

# Send data to database
try:
    for book in books:
        # db.query("ALTER TABLE `top100LC` CHANGE addDate addDate CHAR(34);")

        db.query(
            """INSERT INTO `top100lc` (Title, Author, Rank, Readers, Opinions, Rate, addDate)
									VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', NOW())""".format(
                book[0], book[1], book[2], book[3], book[4], book[5]))

    print("\nSuccessful send data to database")
except:
    print("\nCan't send data to database")

# Close database connect
db.close()
Beispiel #2
0
def process():
    output_folder = os.getcwd() + "/../video/output/"
    # Take the new video and move it to the output folder
    for video in get_list_of_files(config("General.SourcePath")):
        # Get the camera number from the video path
        camera_number = video.split('/')[-3]

        # Check if the camera is enabled, if not delete the video and return
        if not camera_config(camera_number, "Enabled", "bool"):
            log("Camera is not enabled", "info")
            os.unlink(video)
            return False, None

        # Create video Model
        database = Database()

        event_id = database.createEvent({
            'filename': path.basename(video),
            'timestamp': datetime.now()
        })

        # Prepare the frames for further analysis
        video_folder, total_frames, frames = prepare_video(
            video, output_folder, event_id)

        frames_interval = camera_config(camera_number, "FramesInterval")

        attributes = {
            'video_folder': path.basename(video_folder),
            'total_frames': total_frames,
            'skipped_frames': frames_interval,
            'camera': camera_number
        }

        # If we want to notify in any case, let's skip the object detection
        if camera_config(camera_number, "NotifyAlways", "bool"):
            database.updateEvent(event_id, attributes)
            return frames[1], camera_number

        # Now that we have extracted the frames from the video, let's start the analysis
        outcome = False
        frame_counter = 0
        for frame in frames:
            frame_counter = frame_counter + 1
            log("analysing: " + frame, "debug")
            outcome, attributes = analyse_image(
                camera_number, frame, video_folder, attributes)
            if outcome:
                log("object found", "info")
                attributes['frame'] = frame_counter * int(frames_interval)
                break

        # If the outcome is not True, delete the folder with the video and frames
        if not outcome:
            log("No object found", "info")
            if camera_config(camera_number, "DeleteVideosIfNothingFound", "bool"):
                log("Deleting {}".format(video_folder), "info")
                shutil.rmtree(video_folder, ignore_errors=True)

        # Serialize the labels
        try:
            attributes['labels_found'] = json.dumps(
                attributes['labels_found'], cls=JsonHelper)
        except:
            log('could not dump the attributes to array. Probably the attributes obj did not have the labels_found key', 'error')

        database.updateEvent(event_id, attributes)
        database.close()
        return outcome, camera_number
    return None, None