-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
181 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -ex | ||
|
||
rm -f output/subscription_list.tex | ||
python subscribers_list.py | ||
cd output | ||
pdflatex subscription_list.tex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import requests | ||
import json | ||
from jinja2 import Environment, FileSystemLoader | ||
|
||
# Define the API endpoint URL | ||
api_url = "http://localhost:8081/api/subscription/list.php" | ||
|
||
# Make a GET request to the API | ||
response = requests.get(api_url) | ||
|
||
# Check if the request was successful (status code 200) | ||
if response.status_code == 200: | ||
# Parse the JSON response | ||
data = json.loads(response.text) | ||
|
||
# Check if the API response contains data | ||
if 'data' in data: | ||
subscriptions = data['data'] | ||
|
||
# Create a Jinja2 environment | ||
env = Environment(loader=FileSystemLoader('.')) | ||
|
||
# Load the LaTeX template | ||
template = env.get_template('subscription_template.tex') | ||
|
||
for subscription in subscriptions: | ||
image_url = subscription["qr"] | ||
# response = requests.get(image_url) | ||
|
||
tex_file_path = f"images/{image_url.split('/')[-1]}" | ||
local_file_path = f"./output/{tex_file_path}" | ||
# image_data = response.content | ||
|
||
subscription["qr_filename"] = f"./{tex_file_path}" | ||
|
||
# Save the image to the local file | ||
# with open(local_file_path, 'wb') as file: | ||
# file.write(image_data) | ||
|
||
|
||
# Render the LaTeX document with data | ||
rendered_latex = template.render(subscriptions=subscriptions) | ||
|
||
# Save the rendered LaTeX document to a .tex file | ||
with open("output/subscription_list.tex", "w") as tex_file: | ||
tex_file.write(rendered_latex) | ||
|
||
print("LaTeX document created successfully.") | ||
else: | ||
print("No subscription data found in the API response.") | ||
exit(0) | ||
else: | ||
print("Failed to fetch data from the API. Status code:", response.status_code) | ||
exit(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
\documentclass[a4paper]{article} | ||
|
||
% Include the geometry package to set page layout | ||
\usepackage[margin=1in]{geometry} | ||
\usepackage{graphicx} | ||
\usepackage{longtable} % To support multi-page tables | ||
\usepackage{geometry} % To adjust page margins | ||
\usepackage[utf8]{inputenc} | ||
\usepackage{booktabs,multirow,array} | ||
|
||
% Set custom page margins | ||
\geometry{left=0.5cm, right=0.5cm, top=0.5cm, bottom=0.5cm} | ||
|
||
\begin{document} | ||
\title{Subscription List} | ||
|
||
\begin{longtable}{|c|c|} | ||
\hline | ||
\textbf{Personal Information} & \textbf{QR Code} \\ | ||
\hline | ||
\endhead | ||
{% for subscription in subscriptions -%} | ||
\multirow{3}{*}{ | ||
\begin{tabular}{@{}c@{}} | ||
\texttt{ {{- subscription["person"]["fullname"] -}} } \\ | ||
\texttt{ {{- subscription["person"]["email"].replace("_", "\\_").replace("%", "\\%") -}} } \\ | ||
\texttt{ {{- subscription["person"]["phone"] -}} } | ||
\end{tabular} } & | ||
\begin{tabular}{@{}c@{}} | ||
\setlength{\fboxsep}{20pt} % Adjust the padding here | ||
\fbox{ \includegraphics[width=2in]{ {{- subscription.qr_filename -}} } } | ||
\end{tabular} \\ | ||
\hline | ||
{% endfor %} | ||
\end{longtable} | ||
\end{document} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
require_once dirname(dirname(__DIR__)) . '/lib/subscription.php'; // Adjust the path as needed | ||
|
||
// Set the response content type to JSON | ||
header('Content-Type: application/json'); | ||
|
||
// Fetch subscription data using Subscription::list() | ||
try { | ||
$subscriptions = Subscription::list(["active" => 1]); | ||
|
||
if ($subscriptions === null) { | ||
$response = [ | ||
'success' => true, | ||
'message' => 'No subscriptions found', | ||
'data' => [] | ||
]; | ||
} else { | ||
$response = [ | ||
'success' => true, | ||
'message' => 'Subscriptions retrieved successfully', | ||
'data' => $subscriptions | ||
]; | ||
} | ||
} catch (Exception $e) { | ||
// Handle any exceptions or errors | ||
$response = [ | ||
'success' => false, | ||
'message' => 'Error retrieving subscriptions: ' . $e->getMessage() | ||
]; | ||
} | ||
|
||
// Encode the response array as JSON and print it | ||
echo json_encode($response); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters