조원들과 발표 준비를 했다.

각자 맡은 역할을 했다. 캡스톤 디자인마냥 패널도 하나 만들고, PPT도 만들고, 테이블 정의서도 만들고 등등...

나는 인수인계서를 정리하고 PPT 정리를 돕고 파이썬 코드를 다시 보는 중이다...

'개발자 > TIL' 카테고리의 다른 글

TIL 20.07.23  (0) 2020.07.24
TIL 20.07.22  (0) 2020.07.22
TIL 20.07.20  (0) 2020.07.21
TIL 20.07.17  (0) 2020.07.19
TIL 20.07.16  (0) 2020.07.17

파이썬으로 ETL 하는 것을 거의 끝마쳐간다...

이제 옵저버만 구현하면 끝인데 내일은... 발표 준비를 먼저 해야겠구나...

'개발자 > TIL' 카테고리의 다른 글

TIL 20.07.22  (0) 2020.07.22
TIL 20.07.21  (0) 2020.07.21
TIL 20.07.17  (0) 2020.07.19
TIL 20.07.16  (0) 2020.07.17
TIL 20.07.15  (0) 2020.07.16

1. sh 설치파일을 다운로드 받는다.

CLI 환경이라면 wget으로 설치 파일 링크를 넣고 다운로드한다.

ex ) wget repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh

 

 

2. sh 파일을 실행시킨다.

GUI에서 텍스트 편집기로 열면 하루 종일 설치할지도 모른다.... 엄청 오래걸림...

zsh나 bash 쉘로 실행시킨다.

 

실행 후 계속 'return'키('enter'키)를 누르고 있는다.

누르고 있으면 'Do you accept the license terms?'로 넘어가는데 이 때 'yes'를 입력한다.

 

다음에는 설치 경로를 물어본다. 위치를 지정하고 싶지 않다면 기본으로 나타내주는 경로(여기서는 현재 '/home/parallels/anaconda3')에 그대로 설치한다. 그냥 'return'키('enter'키) 입력.

 

초기화 역시 'yes'를 입력한다.

 

설치가 완료되면 'reboot' 재부팅한다.

 

그리고... 정확한 이유는 모르겠지만 아나콘다 설치하면서 환경설정 건드린게 문제인지 무한 로그인 상태가 발생했다...

해결 방법은 '그놈 클래식(GNOME Classic)'에서는 무한 로그인 입력창에 빠져서 로그인이 안 된다;; '그놈(GNOME)'으로 변경 후 로그인해준다.

 

터미널 앞에 (base)가 붙어 나오면 성공

 

찝찝하면 'python -v'를 입력해본다...

 

아나콘다 덕에 그놈 클래식이 망가져서 그놈을 써보니까 맥이랑 더 유사하다... 맘에 드는걸...?

맥에서는 재부팅 없이 터미널에 환경변수가 잡혔던 것 같은데 왜 리눅스는 재부팅 해야하지 -ㅅ-;;

뭐... 계정 로그인 강제로 다시 해주거나 source 실행 시켜도 되지만 그냥 재부팅이 깔끔한 것 같다...

재부팅을 해보면 혹시라도 환경변수 등록에 문제 있는지도 바로 확인할 수 있으니까...

 

 

 

 

근데 CentOS를 민트처럼 그놈 대신 시나몬으로 바꿀 수는 없는걸까...?

직접 만들기

1. 디렉토리나 파일 갯수를 count 해서 증가하면 명령을 실행하는 등 규칙을 정한다. (파일 값의 수정은 감시 불가)

2. 특정 디렉토리나 파일 자체를 hash해서 hash값이 바뀌면 명령을 실행하도록 한다. (파일 값의 수정도 감시 가능)

 

watchdog 모듈(라이브러리 이용하기)

pypi.org/project/watchdog/

 

watchdog

Filesystem events monitoring

pypi.org

 

기본 폼 1.

wikidocs.net/21049

 

위키독스

온라인 책을 제작 공유하는 플랫폼 서비스

wikidocs.net

import os
import time
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler

class Target:
    watchDir = os.getcwd()
    #watchDir에 감시하려는 디렉토리를 명시한다.

    def __init__(self):
        self.observer = Observer()   #observer객체를 만듦

    def run(self):
        event_handler = Handler()
        self.observer.schedule(event_handler, self.watchDir, 
                                                       recursive=True)
        self.observer.start()
        try:
            while True:
                time.sleep(1)
        except:
            self.observer.stop()
            print("Error")
            self.observer.join()

class Handler(FileSystemEventHandler):
#FileSystemEventHandler 클래스를 상속받음.
#아래 핸들러들을 오버라이드 함

    #파일, 디렉터리가 move 되거나 rename 되면 실행
    def on_moved(self, event):
        print(event)

    def on_created(self, event): #파일, 디렉터리가 생성되면 실행
        print(event)

    def on_deleted(self, event): #파일, 디렉터리가 삭제되면 실행
        print(event)

    def on_modified(self, event): #파일, 디렉터리가 수정되면 실행
        print(event)

if __name__ == ‘__main__’: #본 파일에서 실행될 때만 실행되도록 함
    w = Target()
    w.run()

 

 

기본 폼 2.

import time
import os

try:
    from watchdog.observers import Observer
    from watchdog.events import FileSystemEventHandler
except ModuleNotFoundError as e:
    print (e)
    os.system("pip install watchdog")

# ------------------------------------------------
class Handler(FileSystemEventHandler):
    def on_created(self, event): # 파일 생성시
        print (f'event type : {event.event_type}\n'

               f'event src_path : {event.src_path}')
        if event.is_directory:
            print ("디렉토리 생성")
        else: # not event.is_directory
            """
            Fname : 파일 이름
            Extension : 파일 확장자 
            """
            Fname, Extension = os.path.splitext(os.path.basename(event.src_path))
            '''
             1. zip 파일
             2. exe 파일
             3. lnk 파일
            '''
            if Extension == '.zip':
                print (".zip 압축 파일 입니다.")
            elif Extension == '.exe':
                print (".exe 실행 파일 입니다.")
                os.remove(Fname + Extension)   # _파일 삭제 event 발생
            elif Extension == '.lnk':
                print (".lnk 링크 파일 입니다.")

    def on_deleted(self, event):
        print ("삭제 이벤트 발생")

    def on_moved(self, event): # 파일 이동시
        print (f'event type : {event.event_type}\n')

class Watcher:
    # 생성자
    def __init__(self, path):
        print ("감시 중 ...")
        self.event_handler = None      # Handler
        self.observer = Observer()     # Observer 객체 생성
        self.target_directory = path   # 감시대상 경로
        self.currentDirectorySetting() # instance method 호출 func(1)

    # func (1) 현재 작업 디렉토리
    def currentDirectorySetting(self):
        print ("====================================")
        print ("현재 작업 디렉토리:  ", end=" ")
        os.chdir(self.target_directory)
        print ("{cwd}".format(cwd = os.getcwd()))
        print ("====================================")

    # func (2)
    def run(self):
        self.event_handler = Handler() # 이벤트 핸들러 객체 생성
        self.observer.schedule(
            self.event_handler,
            self.target_directory,
            recursive=False
        )

        self.observer.start() # 감시 시작
        try:
            while True: # 무한 루프
                time.sleep(1) # 1초 마다 대상 디렉토리 감시
        except KeyboardInterrupt as e: # 사용자에 의해 "ctrl + z" 발생시
            print ("감시 중지...")
            self.observer.stop() # 감시 중단

myWatcher = Watcher("C:/Users/samsung/HealthCare")
myWatcher.run()

 

 

파이썬 데이터 불러오고, 조건에 따라 내보내기가 드디어 완성되었다

다음주는 다시 자바를 하면 되겠구나

'개발자 > TIL' 카테고리의 다른 글

TIL 20.07.21  (0) 2020.07.21
TIL 20.07.20  (0) 2020.07.21
TIL 20.07.16  (0) 2020.07.17
TIL 20.07.15  (0) 2020.07.16
TIL 20.07.14  (0) 2020.07.14

오늘도 모듈화... 주피터의 감옥이다

 

'개발자 > TIL' 카테고리의 다른 글

TIL 20.07.20  (0) 2020.07.21
TIL 20.07.17  (0) 2020.07.19
TIL 20.07.15  (0) 2020.07.16
TIL 20.07.14  (0) 2020.07.14
TIL 20.07.13  (0) 2020.07.14

파이썬 모듈화 모듈화 모듈화... 함수로 각각 쪼개서 모듈화 모듈화.....

'개발자 > TIL' 카테고리의 다른 글

TIL 20.07.17  (0) 2020.07.19
TIL 20.07.16  (0) 2020.07.17
TIL 20.07.14  (0) 2020.07.14
TIL 20.07.13  (0) 2020.07.14
TIL 20.07.12  (0) 2020.07.14

오늘은 쿼리를 작성하고 파이썬 코드 모듈화를 하고 있다.

오늘 안으로(?) 아니 내일까지 끝내고 목요일은 다시 전자정부로 돌아가기!

'개발자 > TIL' 카테고리의 다른 글

TIL 20.07.16  (0) 2020.07.17
TIL 20.07.15  (0) 2020.07.16
TIL 20.07.13  (0) 2020.07.14
TIL 20.07.12  (0) 2020.07.14
TIL 20.07.11  (0) 2020.07.11

+ Recent posts