https://gall.dcinside.com/mgallery/board/view/?id=thesingularity&no=401624&page=1

์˜คํ”ˆAI ์†Œ์‹ ๋ชจ๋‹ˆํ„ฐ๋ง ์ฝ”๋“œ ์งฐ๋‹คhttps://gall.dcinside.com/mgallery/board/view/?id=thesingularity&no=401622&page=1 OpenAI์˜ ์†Œ์‹์„ ๋ฐ”๋กœ ๋ณด๋Š” ๋ฒ•gall.dcinside.com



7cf3c028e2f206a26d81f6e441807465




from flask import Flask, jsonify, render_template_string

import requests

import hashlib


app = Flask(__name__)


# ์‚ฌ์ดํŠธ๋งต URL

https://openai.com/sitemap.xml


# ๋งˆ์ง€๋ง‰์œผ๋กœ ํ™•์ธ๋œ ์‚ฌ์ดํŠธ๋งต์˜ ํ•ด์‹œ ๋ฐ ๋‚ด์šฉ

last_sitemap_hash = ""

last_sitemap_content = ""


def fetch_sitemap():

"""Fetches the sitemap and returns its content."""

try:

response = requests.get(SITEMAP_URL)

response.raise_for_status()

return response.text

except requests.RequestException as e:

print(f"Error fetching the sitemap: {e}")

return None


def hash_content(content):

"""Returns a hash of the given content."""

return hashlib.md5(content.encode('utf-8')).hexdigest()


@app.route('/')

def home():

"""A home page with automatic sitemap change detection."""

return render_template_string("""

<html>

<head>

<title>OpenAI Sitemap Monitor</title>

<style>

body { font-family: Arial, sans-serif; margin: 40px; }

#log { margin-top: 20px; }

</style>

</head>

<body>

<h1>OpenAI Sitemap Monitor</h1>

<p>This page automatically checks for changes in the OpenAI sitemap every 30 seconds.</p>

<div id="log"></div>


https://code.jquery.com/jquery-3.6.0.min.js

<script>

var firstCheck = true;


function checkForChanges() {

$.get('/check-sitemap-change', function(data) {

var logEntry = document.createElement('p');

if (data.changed) {

if (!firstCheck) {

logEntry.innerHTML = 'Change detected at ' + new Date().toLocaleTimeString();

logEntry.style.color = 'green';

}

} else {

logEntry.innerHTML = 'No change at ' + new Date().toLocaleTimeString();

logEntry.style.color = 'gray';

}

document.getElementById('log').prepend(logEntry);

firstCheck = false;

});

}


// Check for changes every 30 seconds

setInterval(checkForChanges, 30000);

</script>

</body>

</html>

""")


@app.route('/check-sitemap-change', methods=['GET'])

def check_sitemap_change():

"""Checks if the sitemap has changed since the last check."""

global last_sitemap_hash, last_sitemap_content


sitemap_content = fetch_sitemap()

if sitemap_content:

current_hash = hash_content(sitemap_content)


if last_sitemap_hash and current_hash != last_sitemap_hash:

# Update the last known hash and content, and return that a change was detected

last_sitemap_hash = current_hash

last_sitemap_content = sitemap_content

return jsonify({"changed": True})


# Update the last known hash and content

last_sitemap_hash = current_hash

last_sitemap_content = sitemap_content

return jsonify({"changed": False})

else:

return jsonify({"error": "Unable to fetch sitemap"}), 500


if __name__ == '__main__':

app.run(debug=True)



๋งŒ๋“ ๊ฑฐ์—์„œ ๊ธฐ๋Šฅ ํ•˜๋‚˜์”ฉ ์ข€ ๋” ์ถ”๊ฐ€ํ•ด๋‹ฌ๋ผํ•˜๋‹ˆ๊นŒ ์•„์ฃผ ์ž˜ํ•ด์ฃผ๋…ธ ใ…‹ใ…‹

๋กœ์ปฌ ํŒŒ์ด์ฌ์œผ๋กœ ์‹คํ–‰ํ•˜๋ฉด ์ž˜๋œ๋‹ค

์˜คํ”ˆAI ์ƒˆ ์†Œ์‹ ๋‚˜์˜ค๋ฉด ๋ฐ”๋กœ ์•Œ ์ˆ˜ ์žˆ๊ฒ ๋…ธ.