File size: 1,803 Bytes
876b664
 
 
 
1c64a07
 
3fe250d
 
876b664
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f2f783c
876b664
f2f783c
7f3a0c1
 
 
 
 
 
f2f783c
7f3a0c1
876b664
 
 
 
 
 
 
 
 
 
 
 
 
 
1c64a07
 
 
 
 
 
 
 
 
 
 
 
 
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from io import BytesIO
import requests
import os
from PIL import Image
from github import Github


image_list = []
# Utility Functions to be called from all modules

# Function to return a list of keys of a nested dictionary using it's key value (item or creature)
def keys_list(dict, index):
    keys_list=list(dict.keys())
    return keys_list[index]

# Create a list of a directory if directory exists
def directory_contents(directory_path):
    if os.path.isdir(directory_path) :
          contents = os.listdir(directory_path)
          return contents
    else : pass

# Delete a list of file 
def delete_files(file_paths):
    if file_paths:
     
        for file_path in file_paths:
            if file_path != ".keep":
                try:
                    os.remove(f"./image_temp/{file_path}")
                    print(f"Remove : ./image_temp/{file_path}")
                except OSError as e:
                    print(f"Error: {file_path} : {e.strerror}")
        file_paths.clear()
            

def open_image_from_url(image_url):
    response = requests.get(image_url)
    image_data = BytesIO(response.content)
    image = Image.open(image_data)
    return image

def receive_upload(image_file):
        
    image = Image.open(image_file[0][0])

    print(image)
    return image

def index_image_paths(repo_name,directory_path):
    g = Github()  # No token needed for public repos
    repo = g.get_repo(repo_name)
    contents = repo.get_contents(directory_path)

    files = []
    for content_file in contents:
        if content_file.type == "file":
            media_url = content_file.download_url.replace("raw.githubusercontent.com", "media.githubusercontent.com/media")
            files.append(media_url)  # Or content_file.path for just the path
    
    return files