Exemplo n.º 1
0
def action(request):
    if request.method == 'POST':
        html = request.POST.get('code')
        fname = str(randint(100, 100000))
        fileForShotFile = "./kitkatshotapp/templates/htmlshot/"+fname+".html"
        print(fileForShotFile)
        fileForShot = open(fileForShotFile, "w")
        fileForShot.write(html)
        fileForShot.close()
        # print(html)
        

        client = pdfcrowd.HtmlToImageClient('wrs', '871e6e01dcde0e76e316d47f72916811')
        client.setOutputFormat('png')
        imagefileName = fname+".png"
        htmlshoturl = "/htmlshotview/"+fname

        weburl = "https://kitkatshot.herokuapp.com"+htmlshoturl
        imagefileSaveToAs = "./kitkatshotapp/static/htmlshotimg/"+imagefileName

        client.convertUrlToFile(weburl, imagefileSaveToAs)
        finalOutput = "https://kitkatshot.herokuapp.com/static/htmlshotimg/"+imagefileName
        print("finalOutput:", finalOutput)
        # print(redirecturl)
    return render(request, "public/result.html", {'title': 'KitKatShot', 'image': finalOutput})
Exemplo n.º 2
0
def ping(update, context):
    print("context")
    print(type(context))
    print("update")
    print(update)

    map = src.map.Map()
    map.add_placemark([55.7550256, 48.7445183],
                      hint='Заказ 1',
                      icon_color="#ff0000")
    map.add_placemark([55.7550256, 48.7455183],
                      hint='Заказ 2',
                      icon_color="#0000ff")
    map.add_route([55.7550256, 48.7455183], [55.7550256, 48.7445183])
    map.save_html('test_map.html')

    filename = 'test_image.jpg'
    output_stream = open(filename, 'wb')
    client = pdfcrowd.HtmlToImageClient('ansa1_',
                                        'ca1a906dd7c3e773b52fefcf28aded2d')
    client.setScreenshotWidth(640)
    client.setScreenshotHeight(480)
    client.setOutputFormat('jpg')
    client.convertFileToStream('test_map.html', output_stream)
    output_stream.close()
    context.bot.send_photo(chat_id=update.message.chat_id,
                           photo=open(filename, 'rb'),
                           reply_markup=back_only_markup)
    os.remove('test_map.html')
    os.remove('test_image.jpg')
Exemplo n.º 3
0
 def __init__(self, pdfcrowdData, imgurData):
     self.API = pdfcrowd.HtmlToImageClient(pdfcrowdData[0], pdfcrowdData[1])
     self.API.setOutputFormat('png')
     self.API.setScreenshotWidth(1366)
     self.imgur = ImgurClient(imgurData[0], imgurData[1], imgurData[2],
                              imgurData[3])
     self.workdir = os.getcwd()
Exemplo n.º 4
0
def current_orders(update, context):
    try:
        print(update.message.chat_id)
        # orders = Order.select().where(Order.courier == update.message.chat_id).get()
        map = src.map.Map()
        for order in Order.select().where(
                Order.courier == update.message.chat_id):
            print(order.locationX, order.locationY)
            map.add_placemark([order.locationX, order.locationY],
                              hint='Заказ: {}'.format(order.order_id),
                              icon_color="#ff0000")
        map.save_html('current_orders.html')
        filename = 'current_orders.jpg'
        output_stream = open(filename, 'wb')
        client = pdfcrowd.HtmlToImageClient(
            'ansa1_', 'ca1a906dd7c3e773b52fefcf28aded2d')
        client.setScreenshotWidth(640)
        client.setScreenshotHeight(480)
        client.setOutputFormat('jpg')
        client.convertFileToStream('current_orders.html', output_stream)
        output_stream.close()

        context.bot.send_photo(chat_id=update.message.chat_id,
                               photo=open(filename, 'rb'),
                               reply_markup=back_only_markup)
        os.remove('current_orders.html')
        os.remove('current_orders.jpg')
        return ConversationHandler.END
    except Order.DoesNotExist:
        context.bot.send_message(chat_id=update.message.chat_id,
                                 text=bot_messages.no_orders,
                                 reply_markup=back_only_markup)
        return ConversationHandler.END
Exemplo n.º 5
0
def admin_print_couriers_map(update, context):
    if update.message.chat_id not in managers:
        context.bot.send_message(chat_id=update.message.chat_id,
                                 text=bot_messages.not_admin,
                                 reply_markup=standart_markup)
        return ConversationHandler.END
    print("create map")
    map = src.map.Map()
    for courier in Courier.select():
        print(courier.locationX, courier.locationY)
        map.add_placemark([courier.locationX, courier.locationY],
                          hint='Курьер: {}'.format(courier.courier_id),
                          icon_color="#ff00ff")
    map.save_html('couriers.html')
    print("save map")
    filename = 'couriers.jpg'
    output_stream = open(filename, 'wb')
    client = pdfcrowd.HtmlToImageClient('ansa1_',
                                        'ca1a906dd7c3e773b52fefcf28aded2d')
    client.setScreenshotWidth(640)
    client.setScreenshotHeight(480)
    client.setOutputFormat('jpg')
    client.convertFileToStream('couriers.html', output_stream)
    output_stream.close()
    print("send map image")
    context.bot.send_photo(chat_id=update.message.chat_id,
                           photo=open(filename, 'rb'),
                           reply_markup=admin_functions_markup)
    os.remove('couriers.html')
    os.remove('couriers.jpg')
    return ConversationHandler.END
Exemplo n.º 6
0
def config_convert_img():

    user_api_pdfcrowd = 'mateusas3s'
    key_api_pdfcrowd = '7aa4ecdff52221464868419a3f842b00'

    img_config = pdfcrowd.HtmlToImageClient(user_api_pdfcrowd,
                                            key_api_pdfcrowd)

    # configure the conversion
    img_config.setOutputFormat('jpg')

    return img_config
Exemplo n.º 7
0
def html_to_png(html_list: List[str]):
    # create the API client instance
    settings = config.read('pdfcrowd')
    client = pdfcrowd.HtmlToImageClient(settings['user'], settings['api_key'])

    # configure the conversion
    client.setOutputFormat('png')

    photos = []
    for image in html_list:
        # run the conversion and store the result into the "image" variable
        image = client.convertString(image)
        photos.append(io.BytesIO(image))
    return photos
def convert_html_to_image(html_file):
    username = "******"
    api_key = "9784bd49583665bf62eae49b34748094"
    file_name = ""

    try:
        file_name = 'report.png'
        client = pdfcrowd.HtmlToImageClient(username, api_key)

        client.setOutputFormat('png')

        client.convertFileToFile(html_file, file_name)
        return file_name
    except pdfcrowd.Error as why:
        print(why)
        raise
Exemplo n.º 9
0
def generate_output(url, page):
    s = str(url)
    fl = '%s.html' % str(url)
    di = os.getcwd()
    final = os.path.join(di, fl)

    with open(final, "w") as file:
        file.write(str(page))

## Use pdfcrowd API to convert html to png output
    client = pdfcrowd.HtmlToImageClient('arjunsoin',
                                        '857e0066edce5f22fc537177d3de04a3')
    client.setOutputFormat('png')
    client = client.setScreenshotHeight(1250)
    client.convertFileToFile(final, '%s.png' % str(url))
    return
Exemplo n.º 10
0
    def print(weight, public_price, price_pakke):
        try:

            client = pdfcrowd.HtmlToImageClient(
                'JosepRoo', 'd508735c4b86f87fd4a3961d5195126b')

            # configure the conversion
            client.setOutputFormat('png')

            # run the conversion and store the result into an image variable
            image = client.convertString(
                set_html(weight, public_price, price_pakke))
            temp_buff = BytesIO()
            temp_buff.write(image)
            # need to jump back to the beginning before handing it off to PIL
            temp_buff.seek(0)
            image = Image.open(temp_buff)
            # image = image.resize([720, 1080]) next resolution
            image = image.resize([830, 1133])
            temp_buff.seek(0)
            image.save(temp_buff, format='PNG')
            grf = GRF.from_image(temp_buff.getvalue(), 'ZPL')
            grf.optimise_barcodes()
            import socket
            mysocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            host = "169.254.239.30"
            port = 6101
            print(grf.to_zpl(compression=3, quantity=1))
            try:
                mysocket.connect((host, port))  # connecting to host
                mysocket.send(
                    bytes(grf.to_zpl(compression=3, quantity=1),
                          "utf-8"))  # using bytes
                mysocket.close()  # closing connection
            except:
                print("Error with the connection")
            # Some random options

        except pdfcrowd.Error as why:
            # report the error
            sys.stderr.write('Pdfcrowd Error: {}\n'.format(why))

            # handle the exception here or rethrow and handle it at a higher level
            raise
Exemplo n.º 11
0
    def Map(self):
        import requests
        import folium
        import pdfcrowd
        import sys

        self.URL = 'https://maps.googleapis.com/maps/api/geocode/json?key=AIzaSyBFVqFYHLQNOYuSVfkiHCv1GkyfUpnpAIY' \
              '&sensor=false&language=ko&address={}'.format(self.MountainName)

        self.response = requests.get(self.URL)

        self.data = self.response.json()

        self.lat = self.data['results'][0]['geometry']['location']['lat']
        self.lng = self.data['results'][0]['geometry']['location']['lng']

        self.map_osm = folium.Map(location=[self.lat, self.lng])
        folium.Marker([self.lat, self.lng],
                      popup=self.MountainName).add_to(self.map_osm)
        self.map_osm.save('SearchResultMap.html')

        self.map_url = 'https://www.google.co.kr/maps/search/' + self.MountainName + '/@' + str(
            self.lat) + ',' + str(self.lng) + ',12z'

        messagebox.showinfo("알림", "지도 그리는 중...")

        ############################### html file to png file

        try:
            # create the API client instance
            client = pdfcrowd.HtmlToImageClient(
                'JanghoPark', '2abdd903f12f616c4f8d039230ee1bf1')

            # configure the conversion
            client.setOutputFormat('gif')
            client.setScreenshotWidth(400)
            client.setScreenshotHeight(430)

            # run the conversion and write the result to a file
            client.convertFileToFile('SearchResultMap.html',
                                     'Searched_Result_Map.gif')
        except pdfcrowd.Error as why:
            # report the error
            sys.stderr.write('Pdfcrowd Error: {}\n'.format(why))

            # handle the exception here or rethrow and handle it at a higher level
            raise

        ################################
        #import time
        #time.sleep(5)       # 해결된 줄 알았는데 종종 잘려서 그러질 때가 있음

        self.image = PhotoImage(file='Searched_Result_Map.gif')
        self.window.geometry("800x402")
        self.MapCanvas.create_image(600, 201, image=self.image)

        messagebox.showinfo("알림", "지도가 완성되었습니다!")

        Button(self.window,
               text="구글 지도 연동",
               overrelief="solid",
               width=15,
               command=self.WebViewer).place(x=600, y=350)
Exemplo n.º 12
0
    def mailSend(self):
        global MAIL
        global TEXT
        MAIL = self.e2.get()
        host = "smtp.gmail.com"  # Gmail STMP 서버 주소.
        port = "587"
        messagebox.showinfo("Loading", "이메일 보내는 중...")

        senderAddr = "*****@*****.**"  # 보내는 사람 email 주소.
        recipientAddr = MAIL  # 받는 사람 email 주소.

        msg = MIMEMultipart()

        msg['Subject'] = "산 상세정보"
        msg['From'] = senderAddr
        msg['To'] = recipientAddr

        self.Information()  # 상세정보 누르지 않아도 여기서 다시 실행

        #####################
        import requests
        import folium
        import pdfcrowd
        import sys

        self.URL = 'https://maps.googleapis.com/maps/api/geocode/json?key=AIzaSyBFVqFYHLQNOYuSVfkiHCv1GkyfUpnpAIY' \
                   '&sensor=false&language=ko&address={}'.format(self.MountainName)
        self.response = requests.get(self.URL)
        self.data = self.response.json()
        self.lat = self.data['results'][0]['geometry']['location']['lat']
        self.lng = self.data['results'][0]['geometry']['location']['lng']
        self.map_osm = folium.Map(location=[self.lat, self.lng])
        folium.Marker([self.lat, self.lng],
                      popup=self.MountainName).add_to(self.map_osm)
        self.map_osm.save('SearchResultMap.html')
        #####################
        # 이 부분에서 지도 버튼을 누르지 않아도 folium을 이용한 html파일 생성.

        ############################### html file to png file

        try:
            # create the API client instance
            client = pdfcrowd.HtmlToImageClient(
                'JanghoPark', '2abdd903f12f616c4f8d039230ee1bf1')

            # configure the conversion
            client.setOutputFormat('gif')
            client.setScreenshotWidth(400)
            client.setScreenshotHeight(400)

            # run the conversion and write the result to a file
            client.convertFileToFile('SearchResultMap.html',
                                     'Searched_Result_Map.gif')
        except pdfcrowd.Error as why:
            # report the error
            sys.stderr.write('Pdfcrowd Error: {}\n'.format(why))

            # handle the exception here or rethrow and handle it at a higher level
            raise

        ################################

        text = TEXT
        htmlFileName = "Searched_Result_Map.gif"
        ig = 'Searched_Result_Map.gif'

        # MIME 문서를 생성합니다.
        htmlFD = open(htmlFileName, 'rb')
        igFD = open(ig, 'rb')
        HtmlPart = MIMEText(htmlFD.read(), 'gif', _charset='UTF-8')
        TextPart = MIMEText(text, 'html', _charset='UTF-8')
        igPart = MIMEImage(igFD.read(), 'gif', _charset='UTF-8')
        htmlFD.close()
        igFD.close()
        # 만들었던 mime을 MIMEBase에 첨부 시킨다.
        msg.attach(HtmlPart)
        msg.attach(TextPart)
        msg.attach(igPart)
        # global e, filname
        # filename = filedialog.askopenfilename(initialdir='path', title='select file', filetypes=(('jpeg file, ','*.jpg'), ('all files', '*.*')))
        # path = r'C:\Users\Park\Desktop\SCRIPT\chapter25.pptx'
        # part = MIMEBase("application", "octet-stream")
        # part.set_payload(open(path, 'rb').read())
        # encoders.encode_base64(part)
        # part.add_header('Content-Disposition', 'attachment; filename="%s"'%os.path.basename(path))

        # msg.attach(part)

        # 메일을 발송한다.
        s = mysmtplib.MySMTP(host, port)
        # s.set_debuglevel(1)        # 디버깅이 필요할 경우 주석을 푼다.
        s.ehlo()
        s.starttls()
        s.login("*****@*****.**", "dlsgur932!")
        s.sendmail(senderAddr, [recipientAddr], msg.as_string())
        s.close()

        messagebox.showinfo("Complete", "이메일 보내기 완료!")
Exemplo n.º 13
0
        </style>
        </head>
        <body>
        <p id="header">LottoBot</p>
        <pre id="nums">Numbers:<br>""" + finalNumbers
        
        
        
        html_file = open("picTransform.html", "w")
        html_file.write(htmlContent)
        html_file.close()

        #HTML Conversion to PNG by PdfCrowd
        try:
            # create the API client instance
            client = pdfcrowd.HtmlToImageClient('cellopha_ne', '9246f4e37aaffcee2dd2ab6d6a9e0f27')
        
            # configure the conversion
            client.setOutputFormat('png')
        
           # create output file for conversion result
            output_file = open('numbers.png', 'wb')

            # run the conversion and store the result into an image variable
            image = client.convertFile('picTransform.html')

            # write the image into the output file
            output_file.write(image)

            # close the output file
            output_file.close()
Exemplo n.º 14
0
import pdfcrowd
import sys

try:
    # create the API client instance
    client = pdfcrowd.HtmlToImageClient('demo',
                                        'ce544b6ea52a5621fb9d55f8b542d14d')

    # configure the conversion
    client.setOutputFormat('png')

    # run the conversion and write the result to a file
    client.convertUrlToFile(
        'file:///home/sedna/Downloads/COURSERA-CAPSTONE/map_toronto.html',
        'map_toronto.png')
except pdfcrowd.Error as why:
    # report the error
    sys.stderr.write('Pdfcrowd Error: {}\n'.format(why))

    # handle the exception here or rethrow and handle it at a higher level
    raise
Exemplo n.º 15
0
import pdfcrowd
import sys

try:
    # create the API client instance
    client = pdfcrowd.HtmlToImageClient('temp_user',
                                        '1ce1b6dfd4b0d0c7f3d5b8acce183007')

    # configure the conversion
    client.setOutputFormat('png')

    # run the conversion and write the result to a file
    client.convertFileToFile('output/image.html', 'MyLayout.png')
except pdfcrowd.Error as why:
    # report the error
    sys.stderr.write('Pdfcrowd Error: {}\n'.format(why))

    # handle the exception here or rethrow and handle it at a higher level
    raise
Exemplo n.º 16
0
import pdfcrowd
import sys

try:
    # create the API client instance
    client = pdfcrowd.HtmlToImageClient('Regards', 'a4ba1c683a712b98f7475abcbabb10e5')

    # configure the conversion
    client.setOutputFormat('png')

    # create output file for conversion result
    output_file = open('example.png', 'wb')

    # run the conversion and store the result into an image variable
    image = client.convertFileToFile('/home/vitalikz/Desktop/timetable.html', 'zz.png')

    # write the image the into the output file

    output_file.write(image)

    # close the output file
    output_file.close()
except pdfcrowd.Error as why:
    # report the error to the standard error stream
    sys.stderr.write('Pdfcrowd Error: {}\n'.format(why))