RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题

全部问题

Martin Hope
Vyacheslav
Asked: 2024-11-24 22:57:50 +0000 UTC

屏幕显示的数据与导出到excel文件的数据不一致

  • 6

有一个 Flask 项目:

from flask import Flask, request, render_template, send_file
import requests
# import csv
import pandas as pd
from io import BytesIO
import logging
import json
# import pandas as pd
# from io import BytesIO
# -*- coding: utf-8 -*-
import sys

sys.stdout.reconfigure(encoding='utf-8')

logging.basicConfig(level=logging.DEBUG)
app = Flask(__name__)


# Функция для поиска вакансий
def search_vacancies(keyword):
    BASE_URL = "https://api.hh.ru/vacancies"
    vacancies_found = []  # Список для хранения найденных вакансий
    per_page = 100
    page = 0

    while True:
        params = {
            'text': keyword,
            'page': page,
            'per_page': per_page,
            'only_with_salary': True  # Только вакансии с зарплатой
        }

        response = requests.get(BASE_URL, params=params)
        if response.status_code != 200:
            print("Ошибка при обращении к API")
            break

        lan = response.json()

        if not lan['items']:
            break

        for item in lan['items']:
            # vacancy_name = item['name']
            vacancy_name = item['name'].lower()  # Приводим название вакансии к нижнему регистру для сравнения
            # Проверяем, содержит ли название вакансии ключевое слово
            if keyword in vacancy_name:
                salary_from = item['salary']['from'] if item['salary'] else None
                salary_to = item['salary']['to'] if item['salary'] else None
                currency = item['salary']['currency'] if item['salary'] else None
                city = item['area']['name'] if 'area' in item else None
                link = item['alternate_url'] if 'alternate_url' in item else None
                discription = item['snippet']['responsibility'] if 'snippet' in item else None

                vacancies_found.append({
                    'name': vacancy_name,
                    'salary_from': salary_from,
                    'salary_to': salary_to,
                    'currency': currency,
                    'city': city,
                    'link': link,
                    'discription': discription
                })

        page += 1

    return vacancies_found


@app.route('/download', methods=['POST'])
def download():
    keyword = request.form['work_name']
    vacancies = search_vacancies(keyword)

    df = pd.DataFrame(vacancies)
    output = BytesIO()
    df.to_excel(output, index=False)
    output.seek(0)
    return send_file(output, as_attachment=True, download_name='vacancies.xlsx')


@app.route('/', methods=['GET', 'POST'])
def index():
    if request.method == 'POST':
        keyword = request.form['keyword']
        vacancies = search_vacancies(keyword)
        print(len(vacancies))
        all_vacancies = (len(vacancies))
        if vacancies:
            # filename = save_to_json(vacancies)
            return render_template('index.html', vacancies=vacancies, download=True, all_vacancies=all_vacancies)
        else:
            return render_template('index.html', all_vacancies=0)
    return render_template('index.html')


if __name__ == '__main__':
    app.run(debug=True)
<h1>Парсер вакансий</h1>
<form method="POST">
    <label for="keyword">Введите вакансию для поиска:</label>
    <input type="text" id="keyword" style="margin-left: -2%;" name="keyword" required>
    <button type="submit">Искать</button>
</form>
{% if vacancies %}
<h2>Найденные вакансии: {{ all_vacancies }}</h2>
<form method="post" action="/download">
    <input type="hidden" name="work_name" value="{{ keyword }}">
    <input type="submit" value="Скачать в Excel">
</form>
<table>
    <tr>
        <th>Название</th>
        <th>Зарплата от</th>
        <th>Зарплата до</th>
        <th>Валюта</th>
        <th>Город</th>
        <th>Описание</th>
        <th>Ссылка</th>
    </tr>
    {% for vacancy in vacancies %}
    <tr>
        <td>{{ vacancy.name }}</td>
        <td>{{ vacancy.salary_from }}</td>
        <td>{{ vacancy.salary_to }}</td>
        <td>{{ vacancy.currency }}</td>
        <td>{{ vacancy.city }}</td>
        <td>{{ vacancy.discription }}</td>
        <td><a href="{{ vacancy.link }}" class="vacancy-link">{{ vacancy.link }}</a></td>
    </tr>
    {% endfor %}
</table>
{% elif message %}
<p>{{ message }}</p>
{% endif %}
<form method="post" action="/download">
    <input type="hidden" name="work_name" value="{{ keyword }}">
    <input type="submit" value="Скачать в Excel">
</form>
<!--{#</table>#}-->
</body>
</html>

问题是屏幕上显示的解析结果与导出到excel文件的数据不匹配。而且,我对某个关键字请求不同的数据,并且该关键字对应的数据显示在屏幕上,导出到excel文件的数据总是相同的,尽管它必须与屏幕上显示的数据相对应。我不明白为什么会发生这种情况,如果有人知道,请告诉我问题是什么。

项目链接:https://abram742.pythonanywhere.com/

python
  • 1 个回答
  • 39 Views
Martin Hope
Родион
Asked: 2024-11-24 21:52:51 +0000 UTC

机器人不回复消息

  • 5

我为 TG 机器人编写了一些代码:

import logging
import asyncio
from aiogram import Bot, Dispatcher, types
from aiogram.filters import Command

API_TOKEN = 'тут мой токен'

logging.basicConfig(level=logging.INFO)

bot = Bot(token=API_TOKEN)
dp = Dispatcher()

@dp.message(Command("start"))
async def cmd_start(msg: types.Message):
    await msg.reply("Привет! Я бот, который отвечает на 'привет'.")

@dp.message()
async def echo_message(msg: types.Message):
    if msg.text.lower() == "привет":
        await msg.reply("Привет!")

async def main():
    await dp.start_polling(bot, timeout=10, limit=100)

if __name__ == '__main__':
    asyncio.run(main())

机器人仅响应 /start。没有回应“你好”。怎么了?


现在我坐下来意识到机器人接受所有以“/”开头的消息。我怎样才能让它接受所有消息?

python
  • 1 个回答
  • 13 Views
Martin Hope
Anick
Asked: 2024-11-24 20:27:36 +0000 UTC

Zenject(Unity)如何传递继承自MonoBehaviour的实体?

  • 6
public sealed class GameInstaller : MonoInstaller
{

    public override void InstallBindings()
    {
        this.Container
            .Bind<Lavash>()
            .FromNew()
            .AsSingle();
     }
}

public class Ingredient : MonoBehaviour 
{
  private Lavash select ;   //этот класс наследуется от MonoBehaviour

   [Inject] 
   public void Construct(Lavash _select) 
   { 
     select = _select;  
   }
}

如果您从“Lavash”类中删除 MonoBehaviour,则一切正常。但我需要它。

如果不去掉,则会出现以下错误:

1)

ZenjectException: Assert hit! Invalid type given during bind command.  Expected type 'Lavash' to NOT derive from UnityEngine.Component 
ModestTree.Assert.That (System.Boolean condition, System.String message, System.Object p1) (at Assets/Plugins/Zenject/Source/Internal/Assert.cs:347) 
Zenject.BindingUtil.AssertIsNotComponent (System.Type type) (at Assets/Plugins/Zenject/Source/Binding/BindingUtil.cs:78) 
Zenject.BindingUtil.AssertTypesAreNotComponents (System.Collections.Generic.IEnumerable`1[T] types) (at Assets/Plugins/Zenject/Source/Binding/BindingUtil.cs:117) 
Zenject.FromBinder.FromNew () (at Assets/Plugins/Zenject/Source/Binding/Binders/FromBinders/FromBinder.cs:63) 
GameInstaller.InstallBindings () (at Assets/Scripts/GameInstaller.cs:12) 
Zenject.Context.InstallInstallers (System.Collections.Generic.List`1[T] normalInstallers, System.Collections.Generic.List`1[T] normalInstallerTypes, System.Collections.Generic.List`1[T] scriptableObjectInstallers, System.Collections.Generic.List`1[T] installers, System.Collections.Generic.List`1[T] installerPrefabs) (at Assets/Plugins/Zenject/Source/Install/Contexts/Context.cs:218) 
Zenject.Context.InstallInstallers () (at Assets/Plugins/Zenject/Source/Install/Contexts/Context.cs:139) 
Zenject.SceneContext.InstallBindings (System.Collections.Generic.List`1[T] injectableMonoBehaviours) (at Assets/Plugins/Zenject/Source/Install/Contexts/SceneContext.cs:346) 
Zenject.SceneContext.Install () (at Assets/Plugins/Zenject/Source/Install/Contexts/SceneContext.cs:265) 
Zenject.SceneContext.Validate () (at Assets/Plugins/Zenject/Source/Install/Contexts/SceneContext.cs:121) 
Zenject.Internal.ZenUnityEditorUtil.ValidateCurrentSceneSetup () (at Assets/Plugins/Zenject/Source/Editor/ZenUnityEditorUtil.cs:67) 
UnityEngine.Debug:LogException(Exception) 
ModestTree.Log:ErrorException(Exception) (at Assets/Plugins/Zenject/Source/Internal/Log.cs:60) 
Zenject.Internal.ZenUnityEditorUtil:ValidateCurrentSceneSetup() (at Assets/Plugins/Zenject/Source/Editor/ZenUnityEditorUtil.cs:72) 
Zenject.Internal.ZenUnityEditorUtil:ValidateAllActiveScenes() (at Assets/Plugins/Zenject/Source/Editor/ZenUnityEditorUtil.cs:96) 
Zenject.Internal.<>c:<ValidateAllActiveScenes>b__16_0() (at Assets/Plugins/Zenject/Source/Editor/ZenMenuItems.cs:262) 
Zenject.Internal.ZenUnityEditorUtil:SaveThenRunPreserveSceneSetup(Action) (at Assets/Plugins/Zenject/Source/Editor/ZenUnityEditorUtil.cs:26) 
Zenject.Internal.ZenMenuItems:ValidateAllActiveScenes() (at Assets/Plugins/Zenject/Source/Editor/ZenMenuItems.cs:260)

ZenjectException: Zenject Validation Failed!  See errors below for details. 
Zenject.Internal.ZenUnityEditorUtil.ValidateCurrentSceneSetup () (at Assets/Plugins/Zenject/Source/Editor/ZenUnityEditorUtil.cs:84) 
Zenject.Internal.ZenUnityEditorUtil.ValidateAllActiveScenes () (at Assets/Plugins/Zenject/Source/Editor/ZenUnityEditorUtil.cs:96) 
Zenject.Internal.ZenMenuItems+<>c.<ValidateAllActiveScenes>b__16_0 () (at Assets/Plugins/Zenject/Source/Editor/ZenMenuItems.cs:262) 
Zenject.Internal.ZenUnityEditorUtil.SaveThenRunPreserveSceneSetup (System.Action action) (at Assets/Plugins/Zenject/Source/Editor/ZenUnityEditorUtil.cs:26) 
UnityEngine.Debug:LogException(Exception) 
ModestTree.Log:ErrorException(Exception) (at Assets/Plugins/Zenject/Source/Internal/Log.cs:60) 
Zenject.Internal.ZenUnityEditorUtil:SaveThenRunPreserveSceneSetup(Action) (at Assets/Plugins/Zenject/Source/Editor/ZenUnityEditorUtil.cs:31)
c#
  • 1 个回答
  • 23 Views
Martin Hope
Есть Мнение
Asked: 2024-11-24 18:13:58 +0000 UTC

为什么代码不能正常工作?

  • 5

我正在尝试运行一个代码,该代码将代表我每小时向我的组发送消息。但由于某种原因,它只向我最喜欢的人发送消息,而不向群组发送消息。安装了电话库。告诉我这段代码有什么问题? [![代码运行结果][1]][1]

import time
# Use your own values from my.telegram.org
api_id = 23932115
api_hash = '7dde9279e3c815a7539bb3f3d63942f294'

# The first parameter is the .session file name (absolute paths allowed)
with TelegramClient('anon', api_id, api_hash) as client:
    client.loop.run_until_complete(client.send_message('me', 'Hello, myself!'))

async def main():
    while True:
        await client.send_message(1002172163245, '/Любой текст - тест 33/')

        time.sleep(60)


with client:
    client.loop.run_until_complete(main())
python-3.x
  • 1 个回答
  • 20 Views
Martin Hope
maksim volkov
Asked: 2024-11-24 17:31:57 +0000 UTC

适合初学者的 js 计算器

  • 6
let first = 10;
let last = 5;
let op = '*';

let result = first + op + last;

浏览器拒绝乘法、除法等,我需要在不使用Array的情况下在控制台获取结果,并且数字和乘法需要提示3次

**我尝试的方式**

 function getCacl()
 {
     let firstValue = '';
     let op = '';
     let lastValue = '';

     if(firstValue == ''){
         let firstValue = prompt("type number")
             if(op == ''){
                 let op = prompt("type event")
                     if(lastValue == ''){
                         let lastValue = prompt("type last number")

                         let result = (parseInt(firstValue) + op + parseInt(lastValue))
                         console.log(result );
                     } 
             }
     }

}

javascript
  • 2 个回答
  • 34 Views
上一页
下一页

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5