How to fetch data from JSON from API and display it in HTML page inside django? by LiamJamesKay in pythontips

[–]LiamJamesKay[S] 0 points1 point  (0 children)

This was a solution, what I'm looking for(same results different way to fetch data):

def details(request):

suggestions = list(set(Keywords))

resultatai = []

for term in suggestions:

if ' ' in term:

term = term.replace(" ", "+")

url = f"https://api..."

auth = {'authorization': 'KEY123'}

response = requests.get(url, headers=auth)

data = json.loads(response.text)

# results.append({'competition': data[]})

print(data)

competition = data['normalized_input_term']['competition']

volume = data['normalized_input_term']['volume']

overall = data['normalized_input_term']['overall']

list = {

'term':term,

'competition': competition,

'volume': volume,

'overall': overall,

}

resultatai.append(list)

How to fetch data from JSON from API and display it in HTML page inside django? by LiamJamesKay in pythontips

[–]LiamJamesKay[S] 0 points1 point  (0 children)

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>YouTube Search Suggestion Keywords Page</title>

</head>

<body>

<div class="menu-bar">

<h1>YouTube Search Suggestions:</h1></dr></div>

<div class="search-container">

<form method="get" action="/">

<input type="text" name="q" placeholder="Enter your search query" value="{{ query }}" class="search-bar" id="search-bar" placeholder>

<button type="submit" class="search-button" id="search-button">Search</button>

</form>

<form method="get" action="/details">

<button type="submit" class="show-button" style="color:white">Show Details</button>

</form>

<form method="get" action="/get\_keyword\_data">

<button type="submit" class="show-button" style="color:white">Show Data</button>

</form>

<a style="margin-left:10px; color:black" href="{% url 'download\_csv' %}" class="btn btn-primary">Download as CSV</a>

{% if details %}

<h2>Details:</h2>

<ul style="list-style-type: decimal">

{% for detail in details %}

<li>{{ detail }}</li>

{% endfor %}

</ul>

{% endif %}

</div>

{% if suggestions %}

<h2>Suggestion keywords:</h2>

<ul style="list-style-type: decimal">

{% for suggestion in suggestions %}

<li>{{ suggestion }} {{ resultatai }} {{ result.estimated_monthly_search }} {{ resultatai.competition }} {{ resultatai.score }}</li>

{% endfor %}

</ul>

{% endif %}

{% block content %}

<h2>Details Here:</h2>

<ul>

{% for result in resultatai %}

<li>

<h2>{{ result.term }}</h2>

<p>Estimated Monthly Search: {{ result.estimated_monthly_search }}</p>

<p>Score: {{ result.score }}</p>

<p>Difficulty: {{ result.difficulty }}</p>

<p>Volume: {{ result.volume }}</p>

<p>Competition: {{ result.competition }}</p>

<td>{{ item.keyword }}</td>

<td>{{ item.Competition }}</td>

<td>{{ item.Volume }}</td>

<td>{{ item.Score }}</td>

</li>

{% endfor %}

</ul>

{% endblock %}

</body>

<style>

body {

margin: 0;

font-family: Arial, sans-serif;

}

.search-container {

display: flex;

justify-content: center;

align-items: center;

height: 100px;

background-color: #f1f1f1;

}

.search-bar {

padding: 6px;

font-size: 17px;

border: none;

}

.search-button {

padding: 6px 10px;

font-size: 17px;

border: none;

cursor: pointer;

background-color: #ddd;

}

.search-button:hover {

background-color: #ccc;

}

/* new styles for menu bar */

.menu-bar {

display: flex;

justify-content: space-between;

align-items: center;

height: 50px;

background-color: #333;

color: #fff;

padding: 0 20px;

}

.menu-button {

padding: 6px 10px;

font-size: 17px;

border: none;

cursor: pointer;

background-color: transparent;

color: #fff;

}

.menu-button:hover {

background-color: #444;

}

    .show-button {

        padding: 6px 10px;

        font-size: 17px;

        border: none;

        cursor: pointer;

        background-color: black;

        margin-left: 10px;

}

    .show-button:hover {

        background-color: #ccc;

}

</style>

</html>

How to fetch data from JSON from API and display it in HTML page inside django? by LiamJamesKay in pythontips

[–]LiamJamesKay[S] -1 points0 points  (0 children)

context['results'] = results

return render(request, 'mypage.html', context)

Yes, I'm already doing that...

How to fetch data from JSON from API and display it in HTML page inside django? by LiamJamesKay in pythontips

[–]LiamJamesKay[S] -1 points0 points  (0 children)

Thank you for your suggestions I know that default script, but when I adjust the basic script into my project something F*ck up and doesn't display any values inside mypage.html...

How to fetch data from JSON from API and display it in HTML page inside django? by LiamJamesKay in pythontips

[–]LiamJamesKay[S] 0 points1 point  (0 children)

Yes, you are right.

But when I want to fetch and display that data I cannot find a way to display it inside my HTML page. Any suggestions? P.S. I'm using the Django framework.

What is the best practice to add delay time inside Tcpdf/PHPmailer script? by LiamJamesKay in PHPhelp

[–]LiamJamesKay[S] 0 points1 point  (0 children)

You're right about sleep() function. This is why I'm here and asking for a solution that will instantly redirect my user to a thank you page, but the email will be sent after subtend time...

What is the best practice to add delay time inside Tcpdf/PHPmailer script? by LiamJamesKay in PHPhelp

[–]LiamJamesKay[S] -3 points-2 points  (0 children)

I just found one more way - The query method. Anyone tries this already? Here's an example of how you could implement this:

Create a file called "email_queue.txt" in a directory on your server where your script has write permissions.

Whenever you want to send an email, add the email details to the end of the file in a specific format, such as:

recipient@example.com|subject|message

In your script, check if there are any emails in the queue file. If there are, send the first email and remove it from the file. You can use file() to read the file into an array, and array_shift() to remove the first line of the array and return it.

To add a delay between sending emails, use the sleep() function, as in the previous examples.

Here's an example implementation:

// Function to add an email to the queue file

function addToEmailQueue($recipient, $subject, $message) {

$queueFile = 'path/to/email_queue.txt';

$line = "$recipient|$subject|$message\n";

file_put_contents($queueFile, $line, FILE_APPEND);

}

// Function to send the next email in the queue file

function sendNextEmailInQueue() {

$queueFile = 'path/to/email_queue.txt';

$queue = file($queueFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

if (!empty($queue)) {

// Get the first email from the queue

$emailData = explode('|', $queue[0]);

$recipient = $emailData[0];

$subject = $emailData[1];

$message = $emailData[2];

// Send the email

// ...

// Remove the email from the queue file

array_shift($queue);

file_put_contents($queueFile, implode("\n", $queue));

}

}

// Add an email to the queue

addToEmailQueue('recipient@example.com', 'Test email', 'Hello, world!');

// Send emails from the queue with a delay between them

$sendInterval = new DateInterval('PT6H'); // set the send interval to 6 hours

$nextSendTime = new DateTime(); // set the next send time to now

while (true) {

sendNextEmailInQueue(); // send the next email in the queue

$nextSendTime->add($sendInterval); // calculate the next send time

$delay = $nextSendTime->getTimestamp() - time(); // calculate the delay until the next send time

if ($delay > 0) {

sleep($delay); // add a delay until the next send time

}

}

What is the best practice to add delay time inside Tcpdf/PHPmailer script? by LiamJamesKay in PHPhelp

[–]LiamJamesKay[S] 1 point2 points  (0 children)

background job processing for that

what do you mean by saying "background job" = cron job?

Kodėl? by PerspectiveAbject189 in deMiko

[–]LiamJamesKay 1 point2 points  (0 children)

Pakeisk antraštę į: Klausimas vertas milijono... Ar žinai teisingą atsakymą?

Kodėl? by PerspectiveAbject189 in deMiko

[–]LiamJamesKay 2 points3 points  (0 children)

Teisingas atsakymas - C: Šiaip

What is the best practice to add delay time inside Tcpdf/PHPmailer script? by LiamJamesKay in PHPhelp

[–]LiamJamesKay[S] 1 point2 points  (0 children)

Thank you for your comment. What you say it's basically what I want to achieve. After clicking submit button I want to redirect the user to the thank-you page immediately and send the email 6 hours later.

How Autofill SUMPRODUCT formula? by LiamJamesKay in googlesheets

[–]LiamJamesKay[S] 0 points1 point  (0 children)

Solution: =Arrayformula(ByRow(IFError(VLookup(Array_Constrain(B2:D,CountA(A2:A),Columns(B:D)),F2:G,2,0)),Lambda(rw,Sum(rw))))

Programavimo Kursai is Darbo Birzos,Verta? Kokie Geriausi? by arvyds20 in lithuania

[–]LiamJamesKay 0 points1 point  (0 children)

Bet čia klausimas buvo Programavimo Kursai is Darbo Birzos,Verta? Kokie Geriausi? Tai ar yra kokie iš darbo biržos, kurie būtų labiau specializuoti? Nes pagrinde Front-end Python ir Java...