Sunday, 9 June 2024

PAWS and Commons

 File Uploading to commons



Steps

Log in PAWS

Upload all files that are to be uploaded to commons in a folder.

For example : Here folder name is :Commons

I uploaded all pdf files there.


Then Create a python file : Example in the same folder.

I saved as upload_image.py  (You can have your own names)

Step 2

Paste the following code

import os

import pywikibot

from pywikibot.specialbots import UploadRobot


# Define the site

site = pywikibot.Site('commons', 'commons')


# Directory containing the files to upload

directory = '/home/paws/Commons/'


# List of files to upload

files_to_upload = [

    '1 (2).pdf',

    '1 (5).pdf'

]


# Iterate over the files and upload each one

for i, filename in enumerate(files_to_upload):

    file_path = os.path.join(directory, filename)


    # Generate the target filename

    target_filename = f'climate_worksheet_{i+1}.pdf'


    # Description of the file

    description = '''== {{int:filedesc}} ==

{{Information

|description={{en|1=CLimate worksheet done by Ali K3 is a remix of imageClimate change-environment.jpgby user:U3196787CC-BY-SA-4.0 CC0. Licensed CC BY SA 4.0.

}}

|source={{own}}

|author=[[User:Akbarali|Akbarali]]

|date=2024-06-09

|permission=

|other versions=

}}


== {{int:license-header}} ==

{{self|cc-by-sa-4.0}}


[[Category:Climate Educational worksheets]]

[[Category:Open Remix: Exploring Knowledge and Cultural Creativity]]

[[Category:Map worksheets]]

[[Category:Educational resources]]

[[Category:Humanities]]


'''


    # Create an instance of the upload bot

    bot = UploadRobot(url=[file_path],

                      description=description,

                      use_filename=target_filename,

                      keep_filename=True,

                      verify_description=False,

                      target_site=site)


    # Run the upload bot

    bot.run()

Step 3
Open Terminal and enter the following

@PAWS:~/Commons$ python upload_image.py  



NB: Give proper file names

0 comments:

Post a Comment