केस का उपयोग करें

/

पर्सनल टास्क ऑटोमेशन

नियमित कार्यों को कारगर बनाने और दक्षता बढ़ाने के लिए कस्टम स्क्रिप्ट और टूल बनाएं

मॉडल

क्लाउड 3.7 सॉनेट

एक क्रॉस-प्लेटफ़ॉर्म पायथन स्क्रिप्ट लिखें जो हर घंटे मेरे डाउनलोड फ़ोल्डर को स्कैन करती है और स्वचालित रूप से नाम बदल देती है और छवि फ़ाइलों को डेट-स्टैम्प्ड सबफ़ोल्डर में ले जाती है।

Query आज़माएं
क्लाउड 3.7 सॉनेट
/
कोडर

स्वचालित छवि फ़ाइल ऑर्गनाइज़र

यहां एक क्रॉस-प्लेटफ़ॉर्म पायथन स्क्रिप्ट है जो हर घंटे आपके डाउनलोड फ़ोल्डर को स्कैन करती है, छवि फ़ाइलों की पहचान करती है, और उन्हें उनके निर्माण/संशोधन तिथियों के आधार पर डेट-स्टैम्प्ड सबफ़ोल्डर में व्यवस्थित करती है:

1import os
2import shutil
3import time
4import datetime
5import schedule
6import platform
7import logging
8from pathlib import Path
9from PIL import Image
10from PIL.ExifTags import TAGS
11
12# Set up logging
13logging.basicConfig(
14    level=logging.INFO,
15    format='%(asctime)s - %(levelname)s - %(message)s',
16    handlers=[
17        logging.FileHandler("image_organizer.log"),
18        logging.StreamHandler()
19    ]
20)
21
22def get_downloads_folder():
23    """Get the downloads folder path based on the operating system"""
24    if platform.system() == "Windows":
25        return os.path.join(os.path.expanduser("~"), "Downloads")
26    elif platform.system() == "Darwin":  # macOS
27        return os.path.join(os.path.expanduser("~"), "Downloads")
28    else:  # Linux and other Unix-like
29        return os.path.join(os.path.expanduser("~"), "Downloads")
30
31def get_image_date(file_path):
32    """Extract date from image metadata or use file modification date"""
33    try:
34        # Try to get date from EXIF data
35        with Image.open(file_path) as img:
36            exif_data = img._getexif()
37            if exif_data:
38                for tag_id, value in exif_data.items():
39                    tag = TAGS.get(tag_id, tag_id)
40                    if tag == "DateTimeOriginal":
41                        # Parse the date string (format: YYYY:MM:DD HH:MM:SS)
42                        date_str = value.split()[0].replace(":", "-")
43                        return date_str
44    except (AttributeError, KeyError, IndexError, TypeError, OSError):
45        pass
46    
47    # Fall back to file modification time
48    mod_time = os.path.getmtime(file_path)
49    date_str = datetime.datetime.fromtimestamp(mod_time).strftime('%Y-%m-%d')
50    return date_str
51
52def is_image_file(file_path):
53    """Check if the file is an image based on extension"""
54    image_extensions = {'.jpg', '.jpeg', '.png', '.gif', '.bmp', '.tiff', '.webp', '.heic'}
55    return os.path.splitext(file_path.lower())[1] in image_extensions
56
57def organize_images():
58    """Scan downloads folder and organize images into date-based folders"""
59    downloads_folder = get_downloads_folder()
60    logging.info(f"Scanning {downloads_folder} for images...")
61    
62    # Create a base folder for organized images
63    organized_folder = os.path.join(downloads_folder, "Organized_Images")
64    if not os.path.exists(organized_folder):
65        os.makedirs(organized_folder)
66    
67    # Get all files in downloads folder
68    files = [f for f in os.listdir(downloads_folder) if os.path.isfile(os.path.join(downloads_folder, f))]
69    
70    # Counter for renamed files
71    moved_count = 0
72    
73    for file_name in files:
74        file_path = os.path.join(downloads_folder, file_name)
75        
76        # Skip the script itself and non-image files
77        if not is_image_file(file_path):
78            continue
79            
80        try:
81            # Get date from image
82            date_str = get_image_date(file_path)
83            
84            # Create date folder if it doesn't exist
85            date_folder = os.path.join(organized_folder, date_str)
86            if not os.path.exists(date_folder):
87                os.makedirs(date_folder)
88            
89            # Generate a unique name for the file
90            file_ext = os.path.splitext(file_name)[1]
91            new_file_name = f"{date_str}_{int(time.time())}_{moved_count}{file_ext}"
92            new_file_path = os.path.join(date_folder, new_file_name)
93            
94            # Move and rename the file
95            shutil.move(file_path, new_file_path)
96            logging.info(f"Moved: {file_name} -> {new_file_path}")
97            moved_count += 1
98            
99        except Exception as e:
100            logging.error(f"Error processing {file_name}: {str(e)}")
101    
102    logging.info(f"Organized {moved_count} images")
103
104def main():
105    """Main function to schedule and run the image organization task"""
106    logging.info("Image Organizer started")
107    
108    # Run once at startup
109    organize_images()
110    
111    # Schedule to run every hour
112    schedule.every(1).hour.do(organize_images)
113    
114    # Keep the script running
115    while True:
116        schedule.run_pending()
117        time.sleep(60)  # Check every minute
118
119if __name__ == "__main__":
120    main()

इस स्क्रिप्ट का उपयोग कैसे करें

  1. आवश्यक पैकेज इंस्टॉल करें:
1pip install pillow schedule
  1. स्क्रिप्ट चलाएँ:
    • यह आपके ऑपरेटिंग सिस्टम के आधार पर स्वचालित रूप से आपके डाउनलोड फ़ोल्डर का पता लगाएगा
    • छवियाँ आपके डाउनलोड फ़ोल्डर में “Organized_Images” नामक फ़ोल्डर में व्यवस्थित की जाएंगी
    • प्रत्येक छवि को उसकी निर्माण तिथि (YYYY-MM-DD) नाम के सबफ़ोल्डर में रखा जाएगा
    • पैटर्न के साथ छवियों का नाम बदल दिया जाएगा: Date_timestamp_counter.extension
  2. विशेषताएँ:
    • क्रॉस-प्लेटफ़ॉर्म (विंडोज, मैकओएस और लिनक्स पर काम करता है)
    • छवि तिथि निर्धारित करने के लिए उपलब्ध होने पर EXIF डेटा का उपयोग करता है
    • EXIF डेटा उपलब्ध नहीं होने पर फ़ाइल संशोधन तिथि पर वापस आ जाता है
    • कंसोल और लॉग फ़ाइल दोनों में सभी क्रियाओं को लॉग करता है
    • शुरू होने पर एक बार चलता है और फिर हर घंटे बाद चलता है
    • त्रुटियों को इनायत से संभालता है
  3. स्क्रिप्ट को बैकग्राउंड में चलाने के लिए:
    • विंडोज़ पर: शेड्यूल किया गया कार्य बनाएं
    • macOS/Linux पर: क्रॉन जॉब्स का उपयोग करें या एक सेवा बनाएं

स्क्रिप्ट तब तक चलती रहेगी जब तक आप इसे रोक नहीं देते हैं, हर घंटे अपने डाउनलोड फ़ोल्डर की जांच करते हैं और किसी भी नई छवि फ़ाइलों को व्यवस्थित करते हैं।

संबंधित उपयोग के मामलों का अन्वेषण करें

उपयोग केस देखें
स्वास्थ्य देखभाल नवाचारों पर शोध मार्गदर्शन प्रदान करने के लिए देखी गई साइटों की छवि

एकेडेमिया

मैं हाल ही में स्वास्थ्य देखभाल के नवाचारों और रोगी देखभाल पर उनके प्रभाव के बारे में एक पेपर पर काम कर रहा हूं। मुझे इस क्षेत्र में हुई सबसे महत्वपूर्ण प्रगति पर मार्गदर्शन चाहिए, जिसमें तकनीकी, फार्मास्युटिकल और प्रक्रियात्मक नवाचार शामिल हैं। कृपया स्वास्थ्य देखभाल नवाचारों की वर्तमान स्थिति का व्यापक अवलोकन प्रदान करें, जिसमें उनके लाभ, चुनौतियां और भविष्य की दिशाएं शामिल हैं। इसके अतिरिक्त, आगे की जांच के लिए प्रासंगिक शोध प्रश्न, कार्यप्रणाली और संभावित स्रोतों का सुझाव दें। मार्गदर्शन को स्पष्ट और संक्षिप्त तरीके से संरचित किया जाना चाहिए, जिसमें विषय का परिचय दिया जाए, नवाचारों का विस्तृत विश्लेषण किया जाए और भविष्य के शोध के लिए सिफारिशें दी जाएं।

निंजा के AI सहायक का अनुभव करें

आज ही मुफ्त में आजमाएं। $19/माह से शुरू होने वाली योजनाएँ।