ghostscripts in python with watchdog

2020-02-12 Thread legaulph
I'm trying to use ghostscripts with python watchdog.

I want to duplicate the last page of a pdf to another directory using the
same name as the source pdf + page number.

So watchdog will monitor the directory for the pdf and ghostscript will copy
the last page to another directory.

I have this, and not able to figure out how to change the output name and
location.

 

import sys

import os

import time

import logging

from watchdog.observers import Observer

from watchdog.events import LoggingEventHandler

from watchdog.events import PatternMatchingEventHandler

 

if __name__ == "__main__":

patterns = "*"

ignore_patterns = ""

ignore_directories = False

case_sensitive = True

my_event_handler = PatternMatchingEventHandler(patterns,
ignore_patterns, ignore_directories, case_sensitive)

def on_created(event):

number_of_pages = 4

input_pdf = event.src_path

for i in range(4, number_of_pages +1):

os.system("gswin64c -q -dBATCH -dNOPAUSE
-sOutputFile=page{page:04d}.pdf"

" -dFirstPage={page} -dLastPage={page}"

" -sDEVICE=pdfwrite {input_pdf}"

.format(page=i, input_pdf=input_pdf))

 

my_event_handler.on_created = on_created

 

path = "."

go_recursively = True

my_observer = Observer()

my_observer.schedule(my_event_handler, path, recursive=go_recursively)

 

my_observer.start()

try:

while True:

time.sleep(1)

except KeyboardInterrupt:

my_observer.stop()

my_observer.join()

 

-- 
https://mail.python.org/mailman/listinfo/python-list


RE: ghostscripts in python with watchdog

2020-02-14 Thread legaulph
I'm not sure what happens, when I'm testing and suddenly I will start
getting this error.
Error: /undefinedfilename in (1)
Operand stack:

Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--
--nostringval--   2   %stopped_push   --nostringval--   --nostringval--
--nostringval--  
 false   1   %stopped_push
Dictionary stack:
   --dict:732/1123(ro)(G)--   --dict:0/20(G)--   --dict:75/200(L)--
Current allocation mode is local
Last OS error: No such file or directory
GPL Ghostscript 9.50: Unrecoverable error, exit code 1


-Original Message-
From: Python-list  On
Behalf Of Bheesham Persaud
Sent: Friday, February 14, 2020 1:26 AM
To: [email protected]
Subject: Re: ghostscripts in python with watchdog

Hey!

If you change the "-sOutputFile` parameter you pass into gswin64c.

For example, something like:

 output_directory = os.path.join(os.path.dirname(input_src), "out")

And then you should be able to modify the call to `os.system` to something
like:

 os.system(
 "gswin64c -q -dBATCH -dNOPAUSE"
 "-sOutputFile={output_directory}/page{page:04d}.pdf"
 " -dFirstPage={page} -dLastPage={page}"
 " -sDEVICE=pdfwrite {input_pdf}"
 .format(
 page=i,
 input_pdf=input_pdf,
 output_directory=output_directory
 )
 )
--
https://mail.python.org/mailman/listinfo/python-list

-- 
https://mail.python.org/mailman/listinfo/python-list


RE: ghostscripts in python with watchdog

2020-02-14 Thread legaulph
I see it does not like spaces in the file name

-Original Message-
From: [email protected]  
Sent: Friday, February 14, 2020 7:55 AM
To: 'Bheesham Persaud' ; [email protected]
Subject: RE: ghostscripts in python with watchdog

I'm not sure what happens, when I'm testing and suddenly I will start
getting this error.
Error: /undefinedfilename in (1)
Operand stack:

Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--
--nostringval--   2   %stopped_push   --nostringval--   --nostringval--
--nostringval--  
 false   1   %stopped_push
Dictionary stack:
   --dict:732/1123(ro)(G)--   --dict:0/20(G)--   --dict:75/200(L)--
Current allocation mode is local
Last OS error: No such file or directory GPL Ghostscript 9.50: Unrecoverable
error, exit code 1


-Original Message-
From: Python-list  On
Behalf Of Bheesham Persaud
Sent: Friday, February 14, 2020 1:26 AM
To: [email protected]
Subject: Re: ghostscripts in python with watchdog

Hey!

If you change the "-sOutputFile` parameter you pass into gswin64c.

For example, something like:

 output_directory = os.path.join(os.path.dirname(input_src), "out")

And then you should be able to modify the call to `os.system` to something
like:

 os.system(
 "gswin64c -q -dBATCH -dNOPAUSE"
 "-sOutputFile={output_directory}/page{page:04d}.pdf"
 " -dFirstPage={page} -dLastPage={page}"
 " -sDEVICE=pdfwrite {input_pdf}"
 .format(
 page=i,
 input_pdf=input_pdf,
 output_directory=output_directory
 )
 )
--
https://mail.python.org/mailman/listinfo/python-list


-- 
https://mail.python.org/mailman/listinfo/python-list


RE: How to get a place's longitude and latitude?

2020-02-24 Thread legaulph
Try something like

import requests
import json

url =
"https://nominatim.openstreetmap.org/search.php?q=city+country&format=json&l
imit=1"
result = requests.get(url)
dataobj = result.json()
x = dataobj[0]['lat'] + "," + dataobj[0]['lon']
print(x)



-Original Message-
From: Python-list  On
Behalf Of Aakash Jana
Sent: Monday, February 24, 2020 11:08 AM
To: Souvik Dutta 
Cc: [email protected]
Subject: Re: How to get a place's longitude and latitude?

You might use webscraping with requests and beautiful soup to scrape up some
website for that gives such utility


On Mon, 24 Feb 2020, 9:36 pm Souvik Dutta  Hi guys I want to make a program that kinda sends an sos message with 
> the measures of longitude and latitude (which is super inconvenient) 
> to someone. How can I do that I mean how can I get the longitude and
latitude?
> Any help would be appreciated.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
--
https://mail.python.org/mailman/listinfo/python-list

-- 
https://mail.python.org/mailman/listinfo/python-list